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

Armin Rigo arigo at tunes.org
Sun Mar 13 12:05:42 CET 2011


Hi,

Checked in 72ce40f4803c.

Greg, about the second example you reported:

class C(object):
     def __rmul__(self, other):
         other *= 2
         return other
     def __index__(self):
         return 3
print [1] * C()   # -> CPython: [1,1]  PyPy: [1,1,1]

This is obscure.  It works that way because in that particular case,
CPython first tries __mul__/__rmul__ and then tries the internal
sq_repeat slot of the list (which calls C.__index__()).  I think there
is just no way to reproduce this behavior while remaining sane :-/


Armin



More information about the Pypy-dev mailing list