Re:PEP 572: Python assignment expressions has been accepted
by bilboa on Tuesday July 03, 2018 @05:28PM
(#17453736)
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.
I'm reminded of PHP, where (at least in version 5.*) we could write:
(Taken from an old comment https://news.ycombinator.com/item?id=8119419 )