[pypy-dev] wrong precedence of __radd__ vs list __iadd__

Armin Rigo arigo at tunes.org
Sun Mar 13 11:19:30 CET 2011


Hi Philip,

On Sat, Mar 12, 2011 at 5:21 PM, Philip Jenvey <pjenvey at underboss.org> wrote:
> Jython passes the first example. Shouldn't pypy's inplace_add__List_ANY be returning NotImplemented (or whatever the pypy equiv. would be, FailedToImplement?) instead of raising the exception? To allow the binop rules to continue.

Good idea.  Right now, both on CPython and on PyPy,  [].__iadd__(5)
raises TypeError (instead of returning NotImplemented), but
[].__add__(5)  already behaves differently: it raises TypeError on
CPython and returns NotImplemented on PyPy, with the result that
[]+Bar()  does call the __radd__() method on Bar().  So having the
same difference in the __iadd__() method looks like a useful
compromise.  This is particularly true given that it already works on
all sequence types different from lists, because these don't have an
__iadd__() method at all.


Armin



More information about the Pypy-dev mailing list