[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library
pelson.pub at gmail.com
Fri Apr 12 17:57:49 CEST 2013
1) Is there limitation that EnumValues themselves must be immutable?
2) I'm most excited by the prospect of using these Enums as function
defaults. I've not worked it through fully, but I'm guessing the following
>>> class Colors(Enum):
... red = (256, 0, 0)
>>> def fill(color=Colors.red):
>>> from inspect import signature
(color=<EnumValue: Colors.red [value=(256, 0, 0)]>)
3) Enums are generally used for defining constants - Is there a case to be
made for using capitals in the 435 as PEP8 suggests, or are enums a special
4) Is there an easy way to create custom EnumValues subclasses? In
particular it'd be nice to be able to change the __repr__ in some cases to
hide the value itself, which is often not important.
Sorry if this has already been discussed elsewhere (I've only recently
signed up to the dev mailinglist).
On 12 April 2013 16:23, R. David Murray <rdmurray at bitdance.com> wrote:
> On Fri, 12 Apr 2013 10:50:44 -0400, Barry Warsaw <barry at python.org> wrote:
> > Nick brought this up in private email, and my response was basically that
> > iteration order for Enums should not be guaranteed, even if that happens
> > work in the current implementation. The reason why it works in the
> > implementation is purely to provide predictable reprs.
> > Of course, we could sort the values for the repr and remove the sorted()
> > in EnumMetaclass.__iter__() but then we would have to add it back for
> > IntEnums, since we *do* want to make explicit iteration order guarantees
> > IntEnums, as they also have full rich comparisons. I'm just not sure
> > worth it from an implementation point of view.
> > I will update the PEP to make this more clear.
> > >In talking to an existing internet protocol it would be natural to use
> > >IntEnum and this issue would not arise, but I have recently worked on
> > >an application that had *exactly* the above sort of enumeration used
> > >internally, when it would have been totally appropriate to use Enum
> > >than IntEnum. The ap has several places where an ordered comparison
> > >against the enum is used to check if a code is in the error range or
> > Why Enums and not IntEnums? Enums will not have ordered comparisons, but
> > IntEnums will.
> To take advantage of their incommensurability with other Enums. It's
> not a big deal, though; I'm more concerned that the API be internally
> consistent. I presume that one could always define an Enum subclass
> and provide comparison methods if desired :)
> Python-Dev mailing list
> Python-Dev at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev