Using the example below, How can I ensure that any class that inherits the AdderMixin
has the property x
. This would be done at class definition stage.
class AdderMixin:
x: int
@classmethod
def add(cls, other):
return cls.x + other
class B(AdderMixin):
x = 3
class C(AdderMixin):
pass
# I would like an error to be raised by here,
# as C inherited AdderMixin without defining x
print(B.add(4))
print(C.add(5)) # actually errors here.