[Python-ideas] Enums

Steven D'Aprano steve at pearwood.info
Thu Jul 28 22:13:11 CEST 2011


Barry Warsaw wrote:
> On Jul 27, 2011, at 07:21 PM, Guido van Rossum wrote:
> 
>> It's just possible that there's no way to define enums that neither
>> introduced a new (class) scope nor requires a lot of redundant typing.
> 
> Ezio had a very nice suggestion, which I've implemented in my experimental
> branch, e.g.:
> 
>     >>> foo = sys.modules['foo']
>     >>> Colors.inject(foo)
> 
> .inject() takes anything that implements the setattr() protocol.  So that you
> could then do:
> 
>     >>> import foo
>     >>> foo.red
>     Colors.red


I've been reading this thread with a growing sense of dismay. I started 
off excited by the idea that enums would be added to the language, and 
thinking that Raymond's opposition was uncalled for. Then, as more and 
more features and metafeatures have been proposed, I've now changed my 
mind completely and am now with Raymond.

I don't even know what these "enums" actually are any more. Part 
integer, part string, part namespace, part named constant (only not 
actually constant)... It seems to me that people are trying to dump a 
whole lot of only vaguely related functionality into a single concept. 
Including now a proposal to encourage monkey-patching modules by making 
it an official enum method.

For something that is conceptually so simple, this is becoming awfully 
complicated.



-- 
Steven



More information about the Python-ideas mailing list