[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library (original) (raw)

Glenn Linderman v+python at g.nevcal.com
Fri Apr 26 01:59:52 CEST 2013


On 4/25/2013 3:23 PM, Barry Warsaw wrote:

My point is, "days of the week" has a natural ordering, so why wouldn't you use IntEnum for that? Problem solved.

While the ordering is natural, some implementations start from 0, some start from 1, and on the naming side, some start from Sunday, and some start from Monday. So there are lots of opportunities for the numbers vary, and having easy conversions to int which expose those numbers and allow comparisons to integers, is adding problems, not solving them.

On 4/25/2013 3:36 PM, Ethan Furman wrote:

People like things sorted (or am I alone here?) There are three obvious natural orderings:

1 - value 2 - definition order 3 - name And that's my order of preference for them.

So, being blissfully unaware of the implementation issues, not having yet read the implementation, I suggest that the preferred iteration order should be a characteristic of the Enum when defined, and/or that there should be a method to obtain a list in any of the natural orderings (specifying value ordering may add a restriction that the values be orderable, if done at definition time; if done only on retrieval, attempting to access the list by value would raise an exception).

Another possible ordering would be "random", and for enumerations with values that are tuples or lists or hashes, ordering by some specified element would be conceivable. On the other hand, except for "definition" order, all the other possible orderings could be derived externally to the enumeration.

So if enumerations preserve/provide "definition" order, all the others could be implemented externally or as subtypes. "Definition" order, then is the basic ordering for enumerations because it cannot be externally derived, other than by reading the source code.

-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20130425/77113b57/attachment.html>



More information about the Python-Dev mailing list