[Python-ideas] PEP for enum library type?

Antoine Pitrou solipsis at pitrou.net
Wed Feb 13 08:38:43 CET 2013


On Wed, 13 Feb 2013 08:34:21 +0100
Georg Brandl <g.brandl at gmx.net> wrote:
> Am 13.02.2013 08:21, schrieb Antoine Pitrou:
> > On Wed, 13 Feb 2013 00:57:38 +0100
> > Georg Brandl <g.brandl at gmx.net> wrote:
> >> > IMHO, none of these approach the simplicity and explicitness of this API:
> >> > 
> >> > class Color(Enum):
> >> >     RED = 1
> >> >     GREEN = 2
> >> >     BLUE = 3
> >> 
> >> We could even allow
> >> 
> >> class Color(Enum):
> >>     RED = 1
> >>     GREEN = ...       # becomes 2
> >>     BLUE = ...        # 3
> >>     MAGENTA = 5
> >>     FLUFL = ...       # 6
> > 
> > The fact that the ellipsis variant requires *more* typing sounds a bit
> > wrong to me. The common case should be the easiest to type.
> 
> Well, nobody forbids you from writing the integers out.  But one of the
> complaints was that you shouldn't need to know or write the constant
> values (and "..." is shorter than "val()" which was proposed for that
> purpose).

It would still be shorter to type something like:

class Color(Enum):
    values = ('RED', 'GREEN', 'BLUE', 'MAGENTA', 'FLUFL')

> And for stringy enums that argument is void :)

I'm not sure how it's void. What is the proposed syntax for string
enums?

Regards

Antoine.





More information about the Python-ideas mailing list