Author: Armin Rigo <[email protected]>
Branch:
Changeset: r79939:d2674661565e
Date: 2015-10-03 09:43 +0200
http://bitbucket.org/pypy/pypy/changeset/d2674661565e/
Log: Fix for fed018f3c786: there were reasons for why even __radd__ would
fall back to space.add().
diff --git a/pypy/module/__builtin__/interp_classobj.py
b/pypy/module/__builtin__/interp_classobj.py
--- a/pypy/module/__builtin__/interp_classobj.py
+++ b/pypy/module/__builtin__/interp_classobj.py
@@ -272,11 +272,9 @@
return space.w_NotImplemented
return space.call_function(w_meth, w_b)
else:
- # here, if coerce returns a non-W_Instance object as first
- # argument, then give up. The idea is that this strange
- # case should already have been handled by the binaryop()
- # called from descroperation first.
- return space.w_NotImplemented
+ # fall back to space.xxx() if coerce returns a non-W_Instance
+ # object as first argument
+ return getattr(space, objspacename)(w_b, w_a)
rbinaryop.func_name = "r" + name
return binaryop, rbinaryop
@@ -658,7 +656,7 @@
return space.w_NotImplemented
return space.call_function(w_func, w_other)
else:
- return space.w_NotImplemented
+ return space.pow(w_b, w_a, space.w_None)
else:
# CPython also doesn't try coercion in this case
w_func = self.getattr(space, '__rpow__', False)
diff --git a/pypy/module/__builtin__/test/test_classobj.py
b/pypy/module/__builtin__/test/test_classobj.py
--- a/pypy/module/__builtin__/test/test_classobj.py
+++ b/pypy/module/__builtin__/test/test_classobj.py
@@ -425,6 +425,14 @@
return 42
assert B() + B() == 42
+ def test_coerce_reverse(self):
+ class CoerceNumber:
+ def __coerce__(self, other):
+ assert isinstance(other, int)
+ return (6, other)
+ assert 5 + CoerceNumber() == 11
+ assert 2 ** CoerceNumber() == 64
+
def test_binaryop(self):
class A:
def __add__(self, other):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit