How do you specify in a Python parent class that certain fields/methods need to be overridden in the child classes?
Asked
Active
Viewed 654 times
2 Answers
6
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
- 289,723
- 53
- 439
- 496
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
- 242,874
- 37
- 412
- 384