|
|
|
|
|
by bilboa
2905 days ago
|
|
I found the official docs on how python special methods are looked up. https://docs.python.org/3/reference/datamodel.html#special-l... Apparently the runtime is even more picky than I showed. The method has to be defined on the object's type, not in the object's instance dictionary. So, really the lookup is something like: if hasattr(type(a), '__add__'):
The link I provided explains the rationale for bypassing the instance dictionary and `__getattribute__` method. |
|