[Python-Dev] PEP-435 reference implementation
Guido van Rossum
guido at python.org
Wed May 1 18:43:33 CEST 2013
On Wed, May 1, 2013 at 9:18 AM, Tres Seaver <tseaver at palladion.com> wrote:
> I'd be glad to drop both of those in favor of subclassing: I think the
> emphasis on "class-ness" makes no sense, given the driving usecases for
> adopting enums into the stdlib in the first place. IOW, I would vote
> that real-world usecases trump hypothetical purity.
Yeah, this is the dilemma. But what *are* the real-world use cases?
Please provide some.
Here's how I would implement "extending" an enum if subclassing were
red = 1
white = 2
blue = 3
orange = 4
yellow = 5
green = 6
flag_colors = set(Color) | set(ExtraColor)
Now I can test "c in flag_colors" to check whether c is a flag color.
I can also loop over flag_colors. If I want the colors in definition
order I could use a list instead:
ordered_flag_colors = list(Color) + list(ExtraColor)
But this would be less or more acceptable depending on whether it is a
common or esoteric use case.
--Guido van Rossum (python.org/~guido)
More information about the Python-Dev