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~
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to