[Python-ideas] Enums

Guido van Rossum guido at python.org
Fri Jul 29 05:11:42 CEST 2011


On Thu, Jul 28, 2011 at 5:46 PM, Michael Foord <fuzzyman at gmail.com> wrote:
> I agree "named values" would get us *most* of the value, and would both be
> less contentious and provide a common building block for third party
> libraries to build interesting and perhaps esoteric uses on.
>
> I *like* grouped named values (I think they make nice apis to read and use
> when used appropriately), but hey-ho.

These could be two separate features. Named values could be a building
block for a built-in Enum type -- the named value would take care of
the str() and repr(), while the Enum type would only have to take care
of the nice syntax ("class Color(Enum): red = 1; ...") and just create
a bunch of named values in the class scope. The metaclass would do
something like "for key in classdict: classdict[key] = namedvalue(key,
classdict[key])" (though it would probably have to skip certain keys).

-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list