Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mandatory overriding of fields/methods?

Tags:

python

How do you specify in a Python parent class that certain fields/methods need to be overridden in the child classes?

like image 586
Al Bundy Avatar asked Oct 24 '25 18:10

Al Bundy


1 Answers

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')
like image 147
Blender Avatar answered Oct 27 '25 08:10

Blender