[Python-ideas] Enums

Terry Reedy tjreedy at udel.edu
Thu Jul 28 16:39:42 CEST 2011


On 7/27/2011 10:21 PM, Guido van Rossum wrote:
> On Wed, Jul 27, 2011 at 6:12 PM, Nick Coghlan<ncoghlan at gmail.com>  wrote:

>> Yeah, I'd actually be inclined to define such values programmatically
>> rather than writing them out manually like that:
>>
>> _named_colours = dict(
>>   red=0xFF0000,
>>   green=0x00FF00,
>>   blue=0x0000FF,
>> )
>> globals().update((k, namedvalue(k, v)) for k, v in _named_colours)
>
> Eek, no! It will take the average reader way too long to figure out
> that that does.

Eek 2. That could be buried in a global_constants function
global_constants(red=1,green=2,blue=3)

> Static analyzers (which are getting more important)
> are likely to be fooled by it too. Please remember EIBTI.

But this would be even worse for analyzers.

-- 
Terry Jan Reedy




More information about the Python-ideas mailing list