[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library (original) (raw)

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