ясно, что следующее приведет к бесконечному циклу:
class Klaus:
def __getattribute__(self, key):
return getattr(type(self), key)
Однако я не понимаю, почему вызов суперкласса __getattribute__
будет:
class Parent:
def __init__(self):
print("begin __init__")
self._x = 3
print("end __init__")
def __getattribute__(self, attr_name):
superk = super(type(self), self)
boohl = superk.__getattribute__ == self.__getattribute__
print("with age comes wisdom", boohl)
return superk.__getattribute__(attr_name)
class Child(Parent):
def __getattribute__(self, attr_name):
superk = super(type(self), self)
boohl = superk.__getattribute__ == self.__getattribute__
print("this booger is green!", boohl)
return super(type(self), self).__getattribute__(attr_name)
obj = Child()
print("lambda")
print(obj._x)
print("anonymous")