Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r53630:1212ff3d9858
Date: 2012-03-14 17:43 -0700
http://bitbucket.org/pypy/pypy/changeset/1212ff3d9858/

Log:    Test and fix.

diff --git a/pypy/rlib/rarithmetic.py b/pypy/rlib/rarithmetic.py
--- a/pypy/rlib/rarithmetic.py
+++ b/pypy/rlib/rarithmetic.py
@@ -137,8 +137,11 @@
 maxint = int(LONG_TEST - 1)
 
 def is_valid_int(r):
-    return isinstance(r, (int, long)) and (
+    if objectmodel.we_are_translated():
+        return isinstance(r, int)
+    return type(r) in (int, long) and (
         -maxint - 1 <= r <= maxint)
+is_valid_int._annspecialcase_ = 'specialize:argtype(0)'
 
 def ovfcheck(r):
     "NOT_RPYTHON"
diff --git a/pypy/rlib/test/test_rarithmetic.py 
b/pypy/rlib/test/test_rarithmetic.py
--- a/pypy/rlib/test/test_rarithmetic.py
+++ b/pypy/rlib/test/test_rarithmetic.py
@@ -330,6 +330,12 @@
             return a == b
         py.test.raises(MissingRTypeOperation, "self.interpret(f, [42.0])")
 
+    def test_is_valid_int(self):
+        def f(x):
+            return is_valid_int(x) * 2 + is_valid_int(x + 0.5)
+        res = self.interpret(f, [123])
+        assert res == 2
+
 class TestLLtype(BaseTestRarithmetic, LLRtypeMixin):
     pass
 
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to