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

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Apr 28 05:59:25 CEST 2013

Ethan Furman wrote:
> 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
>   2) have a `_init` that the metaclass calls with the args instead of 
> __init__

I don't much like either of those. It would be much nicer if
one could just write an ordinary __init__ method and have it
work as expected.

It's possible to make it work, I think. The __call__ method
of the metaclass is going to have to do something special
anyway, so that Planet(3) can look up and return an existing
instance instead of making a new one. And if it doesn't make
a new instance, it's not going to call the __init__ method.


More information about the Python-Dev mailing list