In addition to bypassing any instance attributes in the interest of correctness, implicit special method lookup generally also bypasses the
__getattribute__()
method even of the object’s metaclass.
The docs mention special methods such as __hash__
, __repr__
and __len__
, and I know from experience it also includes __iter__
for Python 2.7.
To quote an answer to a related question:
"Magic
__methods__()
are treated specially: They are internally assigned to "slots" in the type data structure to speed up their look-up, and they are only looked up in these slots."
In a quest to improve my answer to another question, I need to know: Which methods, specifically, are we talking about?
a+5
will not call__getattribute__
, whilea.__add__(5)
will call it. Fundamentally__getattribute__
is called whenever you use the dot(.
) to access an attribute. – Sidran__getattribute__
also have used withhasattr(obj, method)
method – Blankbook