Enum with nested classes or with types as members

Ethan Furman ethan at stoneleaf.us
Wed Sep 12 01:05:18 EDT 2018


Greetings!

So the stdlib Enum has been around for a few years now.  Has anyone 
written an enum that either had types as members:

   class Types(Enum):
       Int = int
       Str = str

or that had nested classes:

   class Types(Enum):
      class Contained(Enum):
          circle = 1
          square = 2
      class style:
          something = 'yay!'

?

If you have, why?  Were you able to do everything you wanted, or did you 
have to work around any issues?

I'm asking because in doing some work on Enum it became apparent to me 
that having nested classes was not a smooth, satisfying experience, and 
I'm considering treating them the same way as methods (they will no 
longer be converted into members).

So if you use that functionality, tell me now!  :)

--
~Ethan~



More information about the Python-list mailing list