[Python-ideas] PEP for enum library type?

Steven D'Aprano steve at pearwood.info
Thu Feb 14 00:48:23 CET 2013


On 14/02/13 03:38, Antoine Pitrou wrote:
> Le Wed, 13 Feb 2013 14:07:48 +1000,
> Nick Coghlan<ncoghlan at gmail.com>  a écrit :
[...]
>> What's wrong with enum.make? That just accepts the sequence of names
>> namedtuple style, no values specified anywhere.
>
> What's wrong is that TSBOOWTDI. With enum and enum.make, you have two
> different idioms for declaring enums, while a single class-based
> definition style should suffice.

I disagree. enum.make is the more obvious solution, less verbose and IMO nicer looking too. It's explicit that it makes enums, the API is familiar to anyone who has used namedtuple, and it's an expression rather than a statement so it's more flexible. You can't do this with the class-based syntax:

[enum.make(name % i, factory()) for (i, factory) in enumerate(factories)]


Besides, the presence of a second, non-obvious solution is not a violation of One Obvious Way.

I find it amusing that we as a community put so much emphasis on the Zen which ironically includes one of Tim Peter's subtle jokes.

http://bugs.python.org/issue3364

Python is not Perl, but really, there's hardly anything in Python that can't be done two ways if you really try.



-- 
Steven



More information about the Python-ideas mailing list