[issue9401] automatically try forward operations when reverse operations are NotImplemented
R. David Murray rdmur...@bitdance.com added the comment: No, but you could bring it up on python-ideas. (It would have to wait until after the moratorium in any case.) -- nosy: +r.david.murray ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9401 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9401] automatically try forward operations when reverse operations are NotImplemented
Michael Gilbert michael.s.gilb...@gmail.com added the comment: i think that, for example, the default __rsub__ implementation could be: return self + -other which should just do the right thing assuming the addition and negation functions already do the right thing for the class type. anyway, any implementation should leave the option to override the default __r*__ methods, which would keep the implementation backwards compatible as well. can i keep this open as a feature request? thanks, mike -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9401 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9401] automatically try forward operations when reverse operations are NotImplemented
Georg Brandl ge...@python.org added the comment: This might work for (normally) commutative operations like multiplication and addition, but what about those like subtraction? If the interpreter uses the non-reversed method automatically, it has to apply semantics, but the semantics depend on the type and cannot be guessed by the interpreter. Also, even for normally commutative operations some type may want to behave non-commutative. With this in mind, this cannot be implemented without major headaches both for the implementation and backwards compatibility. -- nosy: +georg.brandl resolution: - rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9401 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9401] automatically try forward operations when reverse operations are NotImplemented
New submission from Michael Gilbert michael.s.gilb...@gmail.com: in order to make overrides simpler, and more obvious to average developers, it would be very useful to automatically call the forward operations (e.g. __mul__) when the reverse operations (e.g. __rmul__) are NotImplemented. i spent quite a bit of time trying to discover why x*3 worked (where x is a class that i created with a __mul__ method); whereas 3*x wouldn't. this feature would really help since in most applications the same behavior is expected from forward and reverse operations. for now, i am content with doing this manually, but it would be nice if it were automated. all of my reverse operations just do: def __rmul__( self , other ): return self.__mul__( other ) where i manually check the type of other in the forward operation, and then handle it appropriately. thanks for considering this. best wishes, mike -- components: Interpreter Core messages: 111833 nosy: Michael.Gilbert priority: normal severity: normal status: open title: automatically try forward operations when reverse operations are NotImplemented type: feature request versions: Python 2.5, Python 2.6, Python 2.7, Python 3.1 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9401 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com