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

Ethan Furman ethan at stoneleaf.us
Sun Apr 28 04:29:55 CEST 2013

On 04/27/2013 07:12 PM, Greg Ewing wrote:
> Guido van Rossum wrote:
>> And __init__/__new__ probably shouldn't be
>> overridden.
> Why shouldn't __init__ be overridden? It's the obvious
> way to support Java-style enum-items-with-attributes.

Overriding __init__ is a PITA because __init__ is also called when you do

   Planet(3)  # get EARTH

and __init__ was expecting a gravitational constant and radius (or something like that).

A couple ways around that:

   1) have the metaclass store the args somewhere special (e.g. _args), have __init__ look like `def __init__(self, 
value=None)`, and have the body treat _args as if it were *args

   2) have a `_init` that the metaclass calls with the args instead of __init__


More information about the Python-Dev mailing list