[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

Tim Delaney timothy.c.delaney at gmail.com
Mon Apr 22 01:31:46 CEST 2013


On 22 April 2013 09:02, Nick Coghlan <ncoghlan at gmail.com> wrote:

>
> On 22 Apr 2013 07:50, "Barry Warsaw" <barry at python.org> wrote:
> >
> > On Apr 20, 2013, at 07:10 PM, R. David Murray wrote:
> >
> > >It seems strange to limit a new Python3 feature to the Python2 feature
> > >set.  Just saying :)
> >
> > For a critical feature sure, but I don't put __repr__ or enum item
> iteration
> > order in that category.  There's no need for gratuitous incompatibility
> > either, and attribute name order is just fine.
>
> Iteration order matters a lot if you don't want people complaining about
> enums being broken:
>
>   class Days(enum.Enum):
>     Monday = 1
>     Tuesday = 2
>     Wednesday = 3
>     Thursday = 4
>     Friday = 5
>     Saturday = 6
>     Sunday = 7
>
I'm fine with iteration order being by sorted name by default, so long as
it's easily overrideable by enum subclasses or metaclasses e.g. an IntEnum
should probably iterate in value order.

For definition order, a 3.x-only metaclass could be provided:

class Days(enum.Enum, metaclass=enum.DefinitionOrder):
    Monday = 1
    Tuesday = 2
    Wednesday = 3
    Thursday = 4
    Friday = 5
    Saturday = 6
    Sunday = 7

Tim Delaney
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130422/f5e43a89/attachment.html>


More information about the Python-Dev mailing list