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

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.

-- Greg



More information about the Python-Dev mailing list