[Python-ideas] PEP for enum library type?

Antoine Pitrou solipsis at pitrou.net
Tue Feb 12 16:31:02 CET 2013


Le Tue, 12 Feb 2013 07:21:04 -0800,
Eli Bendersky <eliben at gmail.com> a écrit :
> 
> from enum import Enum
> 
> class Color(Enum):
>   RED, BLUE, GREEN

I think I'd favour a namedtuple-style approach, e.g.:

class Color(Enum):
    fields = ('RED', 'BLUE', 'GREEN')

(which allows you to build enums programmatically too)

Also, I think you have to provide several classes, at least
SequenceEnum and StringEnum, and perhaps also BitmaskEnum.
It makes sense for them to be separate types, 1) because it makes it
explicit how the given enum behaves, 2) because combining integer and
str constants in an enum would be crazy.

Regards

Antoine.





More information about the Python-ideas mailing list