Noticed that someone wrote the listing as follows:
from enum import IntEnum
class Animal(IntEnum):
dog = 1,
cat = 2
And I thought it was a mistake that would lead to a runtime error because the value of the dog was actually a tuple. To my surprise, this works, and Animal.dog.value == 1.
It works:
class Potato(IntEnum):
spud = ()
with an empty tuple that somehow converts to an integer (maybe the splatting argument to call int?).
This does not work:
class Potato(IntEnum):
spud = []
We receive TypeError: int() argument must be a string or a number, not 'list'.
I see this on both python3 and enum34 backport on python 2.
How / why IntEnumor does its metaclass implicitly convert tuples to integers?
source
share