[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

Barry Warsaw barry at python.org
Thu Apr 25 20:44:10 CEST 2013

On Apr 23, 2013, at 03:44 PM, Antoine Pitrou wrote:

>I'm having a problem with the proposed implementation. I haven't found
>any mention of it, so apologies if this has already been discussed:
>>>> from flufl.enum import *
>>>> class C(Enum):
>...  a = 1
>...  b = 2
>>>> C.a.__class__
><class 'flufl.enum._enum.EnumValue'>
>>>> isinstance(C.a, C)
>>>> isinstance(C(1), C)
>It would really be better if instances were actual instances of the
>class, IMO.

Ignore the single argument call syntax for Enums please.  As Eli pointed out,
you have getitem syntax for this and the single argument call syntax is
deprecated.  It will be removed in a future version of flufl.enum and need not
appear in stdlib enum.  TOOWTDI.

C.a and C[1] return the same object, and it seems perfectly natural to me that
this object is *not* an instance of the enum class.  In fact, it seems
completely weird to me that C.a would be an instance of the enum class.  It
seems very rare that a class has attributes that are instances of that class.
It's not even easy to do with traditional syntax.

class Foo:
    a = Foo()
    b = Foo()
    c = Foo()



More information about the Python-Dev mailing list