Consider the following code:
from enum import Enum
class SubclassOfEnum(Enum):
x = 5
print(SubclassOfEnum.x)
class SubSubclassOfEnum(SubclassOfEnum):
y = 6
print(SubSubclassOfEnum.y)
We get an error, TypeError: Cannot extend enumerations,
from: Python36\lib\enum.py", line 436, in _get_mixins_
Because subclassing Enums with members is specifically disallowed.
For general use-cases for Enum check out When and where to use....
For extending Enums (adding members to existing Enums, not subclassing them)...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With