[Python-Dev] a Constant addition to enum
ncoghlan at gmail.com
Wed Aug 7 07:05:26 CEST 2013
On 7 August 2013 07:36, Eli Bendersky <eliben at gmail.com> wrote:
> On Tue, Aug 6, 2013 at 1:42 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
>> A question came up on stackoverflow asking about the Planet example and
>> the need to have the constant G defined in the method instead of at the
>> class level:
>> Since methods and descriptors are immune to enumeration my proposed
>> solution created a Constant descriptor that could be used to keep class
>> level constants at the class level. It's not complex, only about 7 lines.
>> Should we have something like that included in the enum module?
>> If we do include something like that, should it be constant, or should it
>> be more like property? (The important differences from property being that
>> class access still returns the value, not the property itself, and setting
>> the class-level value changes the value but doesn't replace the property.)
> Personally, I dislike all non-simple uses of Enums. One such use is adding
> behavior to them. This can always be split to separate behavior from the
> Enum itself, and I would prefer that. We went to great lengths to ensure
> that things work in expected ways, but heaping additional features (even as
> separate decorators) is just aggravating thiings. So -1 from me.
> Finally, I suggest we exercise restraint in adding more capabilities to
> enums in 3.4; enums are a new creature for Python and it will be extremely
> useful to see them used in the wild for a while first. We can enhance them
> in 3.5, but premature enhancement is IMHO much more likely to do harm than
Agreed. I wouldn't be averse to taking those advanced examples out of
the docs, too.
Like metaclasses, you can do crazy things with enums. "Can" doesn't
mean "should", however. We've had a lot of success with metaclasses by
soft-pedalling them in the standard library, so people only explore
them when they *really* need them. I think we'd be well advised to
pursue a similar path with advanced Enum tricks.
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-Dev