Question: Why is repr(super(class, thing))
different from super(class, thing).__repr__()
?
I've come across something that I think is odd, would be great if someone has an explanation for why this works the way it does.
My question is about how repr
works
class MyInt(int):
pass
one = MyInt(1)
sup = super(MyInt, one)
>>> repr(sup)
"<super: <class 'MyInt'>, <MyInt object>>"
while
>>> sup.__repr__()
'1'
The second is what I expected to come from the first (yes, the quotes are different in each case). Why are these cases of repr
different? I thought repr(x)
just called x.__repr__
.
As far as I know, super
provides an API to the methods of the super class, rather than the super class itself. So it seems to me that my sup
has two __repr__
methods, one which is called by the repr
and one which is under the name __repr__
. Would really appreciate some insight into what's going on here.
super(MyInt, one).__repr__()
andrepr(super(MyInt, one))
are different? – Angrist