[Python-ideas] Missing Core Feature: + - * / | & do not call __getattr__

Stephan Sahm Stephan.Sahm at gmx.de
Fri Dec 4 08:20:15 EST 2015


Dear all,

I just stumbled upon a very weird behaviour of python 2 and python 3. At
least I was not able to find a solution.

*The point is to dynamically define __add__, __or__ and so on via
__getattr__* (for example by deriving them from __iadd__ or similar in a
generic way).
However this very intuitive idea is currently NOT POSSIBLE because * - * /
& | and so on just bypass this standard procedure.

I found two stackoverflow contributions stating this:
http://stackoverflow.com/questions/11629287/python-how-to-forward-an-instances-method-call-to-its-attribute
http://stackoverflow.com/questions/33393474/lazy-evaluation-forward-operations-to-deferred-value

Neither the mentioned posts, nor I myself can see any reason why this is
the way it is, nor how the operators are actually implemented to maybe
bypass this unintuitive behaviour.

Any help? Comments? Ides?

best,
Stephan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151204/28b9bb6e/attachment.html>


More information about the Python-ideas mailing list