[pypy-svn] r38063 - in pypy/dist/pypy/objspace/std: . test
arigo at codespeak.net
arigo at codespeak.net
Wed Feb 7 14:22:39 CET 2007
Author: arigo
Date: Wed Feb 7 14:22:35 2007
New Revision: 38063
Modified:
pypy/dist/pypy/objspace/std/objspace.py
pypy/dist/pypy/objspace/std/test/test_intobject.py
Log:
Test and fix for BINARY_ADD involving int subclasses in the
optimized_int_add version.
Modified: pypy/dist/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objspace.py (original)
+++ pypy/dist/pypy/objspace/std/objspace.py Wed Feb 7 14:22:35 2007
@@ -63,8 +63,7 @@
W_IntObject, add__Int_Int
w_2 = f.popvalue()
w_1 = f.popvalue()
- if isinstance(w_1, W_IntObject) and \
- isinstance(w_2, W_IntObject):
+ if type(w_1) is W_IntObject and type(w_2) is W_IntObject:
try:
w_result = add__Int_Int(f.space, w_1, w_2)
except FailedToImplement:
Modified: pypy/dist/pypy/objspace/std/test/test_intobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_intobject.py (original)
+++ pypy/dist/pypy/objspace/std/test/test_intobject.py Wed Feb 7 14:22:35 2007
@@ -353,6 +353,39 @@
raises(OverflowError,j,sys.maxint+1)
raises(OverflowError,j,str(sys.maxint+1))
+ def test_int_subclass_ops(self):
+ import sys
+ class j(int):
+ def __add__(self, other):
+ return "add."
+ def __iadd__(self, other):
+ return "iadd."
+ def __sub__(self, other):
+ return "sub."
+ def __isub__(self, other):
+ return "isub."
+ def __mul__(self, other):
+ return "mul."
+ def __imul__(self, other):
+ return "imul."
+ def __lshift__(self, other):
+ return "lshift."
+ def __ilshift__(self, other):
+ return "ilshift."
+ assert j(100) + 5 == "add."
+ assert j(100) + str == "add."
+ assert j(100) - 5 == "sub."
+ assert j(100) - str == "sub."
+ assert j(100) * 5 == "mul."
+ assert j(100) * str == "mul."
+ assert j(100) << 5 == "lshift."
+ assert j(100) << str == "lshift."
+ assert (5 + j(100), type(5 + j(100))) == ( 105, int)
+ assert (5 - j(100), type(5 - j(100))) == ( -95, int)
+ assert (5 * j(100), type(5 * j(100))) == ( 500, int)
+ assert (5 << j(100), type(5 << j(100))) == (5 << 100, long)
+ assert (j(100) >> 2, type(j(100) >> 2)) == ( 25, int)
+
def test_special_int(self):
class a:
def __int__(self):
More information about the Pypy-commit
mailing list