How do you specify in a Python parent class that certain fields/methods need to be overridden in the child classes?
Asked
Active
Viewed 534 times
2 Answers
5
You could raise a NotImplementedError:
def my_method(self, arg):
raise NotImplementedError('Implement me')
For properties, you can use the @property decorator:
@property
def my_property(self):
raise NotImplementedError('Implement me as well')
Blender
- 275,078
- 51
- 420
- 480
1
You could look at the abstract base class module.
However, a simpler alternative is just to define a stub implementation that does nothing, or raises NotImplementedError.
BrenBarn
- 228,001
- 34
- 392
- 371