[Python-Dev] enum discussion: can someone please summarize open issues? (original) (raw)
Guido van Rossum guido at python.org
Mon Apr 29 18:42:00 CEST 2013
- Previous message: [Python-Dev] enum discussion: can someone please summarize open issues?
- Next message: [Python-Dev] enum discussion: can someone please summarize open issues?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, Apr 29, 2013 at 6:51 AM, Eli Bendersky <eliben at gmail.com> wrote:
I don't feel strongly about allowing ()-lookup in addition to []-lookup, but in this paragraph the issue of multiple definitions has sneaked in :-) flufl.enum disallows this:
class Color(Enum): red = 1 blue = 2 green = 1 # oops! Has it been decided that this is now allowed?
I don't recall if it was decided. I think it should be possible to create aliases like this. The main thing I care about is that Color.green == Color.red. I wouldn't mind if Color.green ends up as just a different name for the Color.red object. The most common use case is probably providing backwards compatibility with an old version of the enum when renaming something -- e.g. one could write
class Color(Enum): ... turquoise = 42 aqua = turquoise # I can't tell them apart
Here the metaclass would see two different names with the same value (42).
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.
I think it should be A, and the choice should be the first one in definition order.
-- --Guido van Rossum (python.org/~guido)
- Previous message: [Python-Dev] enum discussion: can someone please summarize open issues?
- Next message: [Python-Dev] enum discussion: can someone please summarize open issues?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]