This question arises from reading the answer to Overriding an inherited property setter. Assume the case where I have the base Person
class:
class Person:
def __init__(self, name):
self.name = name
@property
def name(self):
return self._name
@name.setter
def name(self, value):
self._name = value
Following the top-voted answer the correct way to override the setter would be:
class Superhero(Person):
def __init__(self, name):
super().__init__(name)
@Person.name.setter
def name(self, value):
Person.name.fset(self, "Super " + value)
Would there be a difference if instead, the Superhero
class updated the _name
attribute directly? i.e.
class Superhero(Person):
def __init__(self, name):
super().__init__(name)
@Person.name.setter
def name(self, value):
self._name = "Super " + value
(I know, a comment in the referenced question would have been enough but due to reputation I do not have the privileges to ask.)