On 05/05/2013 10:07 AM, � wrote:> I'm chiming in late, but am I the only one 
who's really bothered by the syntax?

class Color(Enum):
     red = 1
     green = 2
     blue = 3

No, you are not only one that's bothered by it. I tried it without assignments until I discovered that bugs are way too easy to introduce. The problem is a successful name lookup looks just like a name failure, but of course no error is raised and no new enum item is created:

--> class Color(Enum):
...     red, green, blue
...

--> class MoreColor(Color):
...     red, orange, yellow
...

--> type(MoreColor.red) is MoreColor
False

--> MoreColor.orange
<MoreColor.orange: 4>   # value should be 5

About the closest you going to be able to get is something like:

def e(_next=[1]):
    e, _next[0] = _next[0], _next[0] + 1
    return e

class Color(Enum):
    red = e()
    green = e()
    blue = e()

and you can keep using `e()` for all your enumerations, since you don't care what actual value each enumeration member happens to get.

--
~Ethan~
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to