[Python-Dev] enum discussion: can someone please summarize open issues?
larry at hastings.org
Mon Apr 29 18:30:35 CEST 2013
On 04/29/2013 06:51 AM, Eli Bendersky wrote:
> flufl.enum disallows this:
> class Color(Enum):
> red = 1
> blue = 2
> green = 1 # oops!
> Has it been decided that this is now allowed? If this is indeed the
> case, then Color(1) is a problem. The options are:
> A. Return either Color.red or Color.green
> B. Throwing an error
> Do we have a decision on this? Personally I think the latter is
> better; the former is error prone and doesn't seem to be useful too often.
> Eli [trying to tie loose ends for updating the PEP].
Would you disallow this too?
red = 1
blue = 2
Color.green = Color.red
IMO the more Pythonic behavior would be to allow multiple names for the
same value, and your example should produce the same result as my
example. I'm not convinced enums are special enough to break the rules.
See also "consenting adults",
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev