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

Guido van Rossum guido at python.org
Thu Apr 25 23:54:54 CEST 2013


On Thu, Apr 25, 2013 at 11:50 AM, Barry Warsaw <barry at python.org> wrote:
> On Apr 23, 2013, at 10:24 AM, R. David Murray wrote:
>
>>> >>> isinstance(C.a, C)
>>> False
>>> >>> isinstance(C(1), C)
>>> False
>>>
>>> It would really be better if instances were actual instances of the
>>> class, IMO.
>>
>>The first False looks correct to me, I would not expect an enum value to be
>>an instance of the class that holds it as an attribute.
>
> Agreed, completely.
>
>>The second certainly looks odd, but what does it even mean to have an
>>instance of an Enum class?
>
> It only looks odd because it's using failed, duplicate, deprecated syntax.
> Does this look similarly odd?
>
>>>> isinstance(C[1], C)
> False
>
> given that ``C[1] is C.a``?

I don't know what's going on, but it feels like we had this same
discussion a week ago, and I still disagree. Disregarding, the C[i]
notation, I feel quite strongly that in the following example:

class Color(Enum):
    red = 1
    white = 2
    blue = 3
    orange = 4

the values Color.red etc. should be instances of Color. This is how
things work in all other languages that I am aware of that let you
define enums.

--
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list