According to some examples I found I'm trying to implement an override of a property
, but the override does not work. I think this is a still obscure topic with few examples and little information about it. Here is my example:
from abc import ABCMeta, abstractmethod
class Person(metaclass=ABCMeta):
@abstractmethod
def __init__(self, name, age):
self.__name = name
self.age = age
@property
def name(self):
return self.__name
@name.setter
def name(self, value):
self.__name = value
class Myself(Person):
def __init__(self, name, age, tel):
super().__init__(name, age)
self.tel = tel
@Person.name.setter
def name(self, value):
super().name = 'override'
class Wife(Person):
def __init__(self, name, age, tel):
super().__init__(name, age)
self.tel = tel
ms = Myself('Matheus Saraiva', 36, '988070350')
wi = Wife('Joice Saraiva', 34, '999923554')
print(ms.name)
If my implementation is correct, the result of print
should be:
>>> override
but the result is:
>>> Matheus Saraiva
That is, apparently the override is not working. What is wrong with my implementation?