[New-bugs-announce] [issue9401] automatically try forward operations when reverse operations are NotImplemented
report at bugs.python.org
Wed Jul 28 19:56:56 CEST 2010
New submission from Michael Gilbert <michael.s.gilbert at 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.
components: Interpreter Core
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 <report at bugs.python.org>
More information about the New-bugs-announce