[Python-Dev] a Constant addition to enum

Eli Bendersky eliben at gmail.com
Tue Aug 6 23:36:27 CEST 2013

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:
> http://stackoverflow.com/q/**17911188/208880<http://stackoverflow.com/q/17911188/208880>
> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130806/80d10406/attachment.html>

More information about the Python-Dev mailing list