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

Ethan Furman ethan at stoneleaf.us
Sun Apr 28 04:29:55 CEST 2013


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



More information about the Python-Dev mailing list