I'd like to raise a NotImplementedError
when trying to set an attribute in a child class. Here's the code for the parent class:
class Parent():
def __init__(self):
self._attribute = 1
@property
def attribute(self):
return self._attribute
@attribute.setter
def attribute(self, value):
self._attribute = value
I see that I can define a Child
which overwrites' Parent
's attribute setter directly by doing any of the following:
class ChildA(Parent):
@Parent.attribute.setter
def attribute(self, value):
raise NotImplementedError('Not implemented.')
class ChildB(Parent):
@property
def attribute(self):
return self._attribute
@attribute.setter
def attribute(self, value):
raise NotImplementedError('Not implemented.')
Is there a difference between any of the above?