[Python-Dev] PEP 435: initial values must be specified? Yes (original) (raw)

Greg Ewing greg.ewing at canterbury.ac.nz
Mon May 6 01:57:13 CEST 2013


Ethan Furman wrote:

--> class Color(Enum): ... red, green, blue ...

--> class MoreColor(Color): ... red, orange, yellow ... --> type(MoreColor.red) is MoreColor False

This argument no longer applies, since we're not allowing enums to be extended.

class Color(Enum): red = e() green = e() blue = e()

and you can keep using e() for all your enumerations, since you don't care what actual value each enumeration member happens to get.

I don't think it's true that people wanting auto-numbering don't care what values they get. Rather, they probably want ordinal values assigned separately and consecutively for each type, as in every other language I'm aware of that provides auto-numbered enums.

If you really don't care what the values are, there's no need for the items to have values at all.

-- Greg



More information about the Python-Dev mailing list