I was trying to extend an enum.Enum class, thinking that since it didn't add new members to the parent class, it might be okay. But it looks like it won't let you extend if there are parent members, even if you don't add any - it checks and throws an exception. Here's a toy example:
import enum # import aenum as enum # aenum doesn't help
class Color(enum.Enum):
RED = "red"
GREEN = "green"
BLUE = "blue"
def displaystr(self):
return self.value
assert Color.GREEN.displaystr() == "green"
green = Color.GREEN
assert green.displaystr() == "green"
class Technicolor(Color):
def displaystr(self):
# bold Technicolor should return uppercase display string!
return super(Technicolor, self).displaystr().upper()
Does the simple fact of creating the subclass "...lead to a violation of some important invariants of types and instances" that the documentation worries about, since members like GREEN would exist in both the parent and subclass context? Or would it be theoretically okay, but it is just, perhaps, hard to cleanly determine whether or not the subclass adds new members so it simply rejects any extension of a parent with members? Since I can't do even the basic case:
class Technicolor(Color):
pass
I can't create the subclass and monkeypatch on the new displaystr() after.
I'll probably be able to support my use case in some other way, but the natural thought was to subclass to modify behaviour only.