[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library (original) (raw)

Ethan Furman ethan at stoneleaf.us
Thu Apr 25 22🔞47 CEST 2013


On 04/25/2013 11:44 AM, Barry Warsaw wrote:

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) False isinstance(C(1), C) False 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.

For me, the getitem syntax on a class seems odd and the call syntax is 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()

Obviously you need a metaclass in there. ;)

-- Ethan



More information about the Python-Dev mailing list