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

Jacco van Dorp j.van.dorp at deonet.nl
Thu Jun 28 03:07:03 EDT 2018

> Greg
> 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

Enum already is callable - it creates Enum subclasses.


Color = Enum("Color", ("RED", "GREEN", "BLUE"))

(or something similar, I didn't check the docs.)

In general, it sounds to me like you already can avoid them becoming
members if you want - simply by making them a property. Therefore,
letting them be members by default doesn't sound weird to me.

As for embedded classes - well, the cannot be subclasses because the
outer class is not instantiated. You could perhaps build a class
decorator that injects the outer class in the inner class' MRO, but
that doesn't sound like code I'd want to debug.

More information about the Python-ideas mailing list