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

Nikolaus Rath Nikolaus at rath.org
Sun Apr 28 02:42:03 CEST 2013


Guido van Rossum <guido at python.org> writes:
> On Sat, Apr 27, 2013 at 10:04 AM, Ethan Furman <ethan at stoneleaf.us> wrote:
>> While this will certainly work, it means you can't have class variables that
>> happen to be the same type as the enum -- so no int in an IntEnum, for
>> example.
>>
>> The solution I like best is the helper class (called, originally enough,
>> enum), and only those items get transformed:
>>
>> class Planet(IntEnum):
>>     MERCURY = enum(1)
>>     VENUS = enum(2)
>>     EARTH = enum(3)
>>     rough_pi = 3     # not transformed
>
> If this means that the most plain vanilla enum definition still has to
> use the enum(i) notation, I'm against it.

I think this is actually a big advantage. It makes it obvious that
something special is going on without having to know that IntEnum uses a
special metaclass.


Best,

   -Nikolaus

-- 
 »Time flies like an arrow, fruit flies like a Banana.«

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C



More information about the Python-Dev mailing list