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

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Apr 21 13:02:13 CEST 2013


Barry Warsaw wrote:

On Apr 13, 2013, at 12:51 PM, Steven D'Aprano wrote:

class Insect(Enum): wasp = wsap = 1 bee = 2 ant = 3

What's the justification for this restriction? I have looked in the PEP, and didn't see one. If you allowed this, there would be no way to look up an enumeration item by value. This is necessary for e.g. storing the value in a database.

Hm. What you really want there isn't two enum objects with the same value, but two names bound to the same enum object. Then looking it up by value would not be a problem.

-- Greg



More information about the Python-Dev mailing list