2

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_

John Kugelman
  • 330,190
  • 66
  • 504
  • 555
Toothpick Anemone
  • 2,267
  • 14
  • 27

1 Answers1

4

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)...

Ethan Furman
  • 57,917
  • 18
  • 142
  • 218