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

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Jun 27 20:22:16 EDT 2018


Guido van Rossum wrote:
> Sounds to me really strange that the nested class would become a member. 
> Probably because everything becomes a member unless it's a function 
> (maybe decorated)?

Maybe it would have been better if Enums got told what type
their members are supposed to be, an only decorated things
of that type.

     class Color(Enum):
         __type__ = int
         RED = 1
         GREEN = 2
         BLUE = 3
         i_get_left_alone = 4.2

Or perhaps this could be made to work somehow:

     class Color(Enum(int)):
         RED = 1
         GREEN = 2
         BLUE = 3
         i_get_left_alone = 4.2

-- 
Greg


More information about the Python-ideas mailing list