[Python-Dev] PEP-435 reference implementation (original) (raw)

Ethan Furman ethan at stoneleaf.us
Wed May 1 06:19:49 CEST 2013


Latest code available at https://bitbucket.org/stoneleaf/aenum.

--> class Color(Enum): ... red = 1 ... green = 2 ... blue = 3

Enum items are virtual attributes looked by EnumType's getattr. The win here is that

--> Color.red.green.blue

no longer works. ;)

Subclassing an implemented Enum class now raises an error (is there a better word than 'implemented'?)

--> class MoreColor(Color): ... cyan = 4 ... magenta = 5 ... yellow = 6

Traceback (most recent call last): File "", line 1, in File "./ref435.py", line 83, in new raise EnumError("cannot subclass an implemented Enum class") ref435.EnumError: cannot subclass an implemented Enum class



More information about the Python-Dev mailing list