I am trying to understand the function of the dunder getattribute and getattr methods. While experimenting, I noticed an unexpected shape attribute showing up in my class. I can't find any explanation for why this is happening.
class X:
def __init__(self, count):
self.count = count
x = X(42)
results in x showing in PyCharm debug mode as:
x = {X}
count = {int}42
whereas
class X:
def __init__(self, count):
self.count = count
def __getattribute__(self, item):
# Calling the super class to avoid recursion
return super(X, self).__getattribute__(item)
def __getattr__(self, item):
return self.__setattr__(item, 'fred')
x = X(42)
results in x showing in PyCharm debug mode as:
x = {X}
count = {int}42
shape = {str} 'fred'
Where did the attribute "shape" come from and what is its purpose?