[pypy-svn] r14265 - in pypy/dist/pypy: annotation translator/test

pedronis at codespeak.net pedronis at codespeak.net
Tue Jul 5 12:23:58 CEST 2005


Author: pedronis
Date: Tue Jul  5 12:23:48 2005
New Revision: 14265

Modified:
   pypy/dist/pypy/annotation/builtin.py
   pypy/dist/pypy/translator/test/test_annrpython.py
Log:
annotation for int(string[,16])



Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py	(original)
+++ pypy/dist/pypy/annotation/builtin.py	Tue Jul  5 12:23:48 2005
@@ -66,8 +66,15 @@
 def builtin_bool(s_obj):
     return constpropagate(bool, [s_obj], SomeBool())
 
-def builtin_int(s_obj):
-    return constpropagate(int, [s_obj], SomeInteger())
+def builtin_int(s_obj, s_base=None):
+    assert (s_base is None or s_base.is_constant() 
+            and s_base.const == 16
+            and s_obj.knowntype == str), "only int(v|string) or int(string,16) expected"
+    if s_base is not None:
+        args_s = [s_obj, s_base]
+    else:
+        args_s = [s_obj]
+    return constpropagate(int, args_s, SomeInteger())
 
 def restricted_uint(s_obj):    # for r_uint
     return constpropagate(pypy.rpython.rarithmetic.r_uint, [s_obj],

Modified: pypy/dist/pypy/translator/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_annrpython.py	(original)
+++ pypy/dist/pypy/translator/test/test_annrpython.py	Tue Jul  5 12:23:48 2005
@@ -1380,6 +1380,13 @@
         s = a.build_types(f, [int])
         assert s == a.bookkeeper.immutablevalue(12)
 
+    def test_int(self):
+        def f(x, s):
+            return int(x) + int(s) + int(s, 16)
+        a = self.RPythonAnnotator()
+        s = a.build_types(f, [int, str])
+        assert s.knowntype == int
+
 
 def g(n):
     return [0,1,2,n]



More information about the Pypy-commit mailing list