[Python-Dev] Enumeration items: mixed types?
steve at pearwood.info
Tue Apr 30 08:15:34 CEST 2013
On Mon, Apr 29, 2013 at 03:50:22PM -0700, Ethan Furman wrote:
> This just doesn't make sense to me:
> --> class Stuff(Enum):
> ... blue = 1
> ... china = 'really big country'
> ... random = (8273.199, 517)
> --> Stuff.blue.name == 'blue'
> --> Stuff.blue.value == 1
> --> Stuff.china.name == 'china'
> --> Stuff.china.value == ???
Quoting the PEP:
"In the vast majority of use-cases, one doesn't care what the actual
value of an enumeration is. But if the value is important, enumerations
can have arbitrary values."
So in the above, Stuff.china.value == 'really big country' and
Stuff.random.value == (8273.199, 517).
Mixing enumeration values like this would be unusual, but it will work.
It's no different from having a list [1, 'really big country',
(8273.199, 517)]. Lists can deal with it, but if you pass a list of
arbitrary types to something that expects a list of ints, it will
More information about the Python-Dev