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

pedronis at codespeak.net pedronis at codespeak.net
Tue Apr 5 14:10:45 CEST 2005


Author: pedronis
Date: Tue Apr  5 14:10:44 2005
New Revision: 10317

Modified:
   pypy/dist/pypy/annotation/builtin.py
   pypy/dist/pypy/translator/test/test_annrpython.py
Log:
somme support for deducing type info from type(.) is X pattern, with test



Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py	(original)
+++ pypy/dist/pypy/annotation/builtin.py	Tue Apr  5 14:10:44 2005
@@ -139,7 +139,18 @@
         raise Exception, 'type() called with more than one argument'
     if s_obj.is_constant():
         return immutablevalue(type(s_obj.const))
-    return SomeObject()
+    r = SomeObject()
+    # hack info
+    bk = getbookkeeper()
+    fn, block, i = bk.position_key
+    annotator = bk.annotator
+    op = block.operations[i]
+    assert op.opname == "simple_call" 
+    assert len(op.args) == 2
+    assert op.args[0] == Constant(type)
+    assert annotator.binding(op.args[1]) == s_obj   
+    r.is_type_of = [op.args[1]]
+    return r
 
 def builtin_str(s_obj):
     return SomeString()

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 Apr  5 14:10:44 2005
@@ -595,6 +595,17 @@
         assert isinstance(s, annmodel.SomeInstance)
         assert s.knowntype is snippet.Exc
 
+    def test_type_is(self):
+        class C(object):
+            pass
+        def f(x):
+            if type(x) is C:
+                return x
+            raise Exception
+        a = RPythonAnnotator()
+        s = a.build_types(f, [object])
+        assert s.knowntype is C
+
     def test_overrides(self):
         import sys
         excs = []



More information about the Pypy-commit mailing list