[Python-ideas] constant/enum type in stdlib

Ethan Furman ethan at stoneleaf.us
Wed Jan 30 23:26:40 CET 2013


On 01/30/2013 01:52 PM, � wrote:
> 2013年1月30日 Eli Bendersky <eliben at gmail.com>:
>> These are more in the domain of implementation details, though, not
>> criticizing the concep?
>> Personally I'd be +0 for a constant type and -1 for an enum type,
> which I consider just useless.
> If a 'constant' type has to be added though, I'd prefer it to be as
> simple as possible and close to what we've been used thus far, meaning
> accessing it as "foo.BAR".
> In everybody's mind it is clear that "foo.BAR" is a constant, and that
> should be preserved.
> Something along these lines:
>>>>> from collections import constant
>>>> STATUS_IDLE = constant(0, 'idle', doc='refers to the idle state')
>>>> STATUS_IDLE
> 0
>>>> str(STATUS_IDLE)
> 'idle'

So you'd have something like:
--> from collections import constant
--> STATUS_IDLE = constant(0, 'idle', doc='refers to the idle state')
--> STATUS_PAUSE = constant(1, 'pause', doc='refers to the pause state')
--> STATUS_RUN = constant(2, 'run', doc='refers to the run state')
?
Absolutely -1 on this. (Although you can certainly implement it now.)
~Ethan~


More information about the Python-ideas mailing list

AltStyle によって変換されたページ (->オリジナル) /