I understand the basic function and use case of __getattr__ method. But I'm having trouble how parameters are passed around inside __getattr__.
I have code
class Wrapper:
def __init__(self, object):
self.wrapped = object
def __getattr__(self, attrname):
print('trace: ' + attrname)
return getattr(self.wrapped, attrname)
x = Wrapper([1, 2, 3])
x.append(4)
print(x.wrapped)
And it prints
trace: append
[1, 2, 3, 4]
Forgive me if my assumption below is incorrect. I assume that the parameter 4 in x.append(4) is somehow passed from the initial call to __getattr__ and then to the call to getattr method and then to the append method of list class. But I'm not sure what exactly is happening. Could someone please clarify the details.