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__
--
~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