In the following code, the method name name
is used three times within the same Person
scope:
class Person:
def __init__(self, name):
self._name = name
@property
def name(self): # name = property(name)
"name property docs"
print('fetch...')
return self._name
@name.setter
def name(self, value): # name = name.setter(name)
print('change...')
self._name = value
@name.deleter
def name(self): # name = name.deleter(name)
print('remove...')
del self._name
In theory, decorators are equal to a name rebinding. It shouldn't affect the scope. So in the above code the last name
method should be the only surviving one that is being transformed by the decorators.
My question is, what mechanism enables the decorators to pick exactly the 'right' method, and not the last method which in theory should override all the previous ones?