[Python-ideas] Should nested classes in an Enum be Enum members?

Ethan Furman ethan at stoneleaf.us
Sun Jul 1 15:47:44 EDT 2018


On 07/01/2018 06:03 AM, Ivan Levkivskyi wrote:> On 27 June 2018 at 15:46, Ethan Furman wrote:

>> [...]
>> So I'm asking the community:  What real-world examples can you offer for either behavior?  Cases where nested
>> classes should be enum members, and cases where nested classes should not be members.
>
> I wanted few times to make an enum of enums. For example:
>
> class  Method(Enum):
>      Powell = 1
>      Newton_CG = 2
>      <few more>
>      class Trust(Enum):
>          Constr = 3
>          Exact = 4
>          <few more>
>
> So that one can write:
>
> minimize(..., method=Method.Powell)
> minimize(..., method=Method.Trust.Exact)  # this currently fails

In such a case, would you want/expect for

--> list(Method)

to return

[<Powel: 1>, <Newton_CG: 2>, ..., <Trust: -something->]

?

--
~Ethan~



More information about the Python-ideas mailing list