[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library
Ethan Furman
ethan at stoneleaf.us
Sun Apr 28 17:48:13 CEST 2013
On 04/27/2013 08:59 PM, Greg Ewing wrote:
>
> 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.
It works beautifully! It's not even complicated because the metaclass __new__ uses object.__new__ to create the
instances, so EnumType.__call__ is /only/ called in cases like Planet(3), or Planet('EARTH').
Sweet!
--
~Ethan~
More information about the Python-Dev
mailing list