[Python-Dev] a Constant addition to enum

Antoine Pitrou solipsis at pitrou.net
Tue Aug 6 23:45:37 CEST 2013

On Tue, 6 Aug 2013 14:36:27 -0700
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:
> >
> > 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.

Agreed. Also, putting constants inside Enum declarations is just
(it doesn't help that the presented "use case" is the typical
schoolbook example that doesn't correspond to any real-world
situation, just like parsing Roman numbers and solving Hanoi tower



More information about the Python-Dev mailing list