Commits

Anonymous committed 0e521e9 Draft

Basic support for list types in signatures

Comments (0)

Files changed (2)

pypy/annotation/types.py

 from pypy.annotation import model
+from pypy.annotation.listdef import ListDef
 
 
 def int():
 
 def str():
     return model.SomeString()
+
+def list(element):
+    listdef = ListDef(None, element, mutated=True, resized=True)
+    return model.SomeList(listdef)

pypy/rlib/test/test_objectmodel.py

     def str_to_int(s):
         return s
 
+def test_signature_list():
+    @signature(types.list(types.int()), returns=types.int())
+    def f(a):
+        return len(a)
+    argtype = getsig(f)[0]
+    assert isinstance(argtype, model.SomeList)
+    item = argtype.listdef.listitem
+    assert item.s_value == model.SomeInteger()
+
+    @check_annotator_fails
+    def ok_for_body():
+        f(['a'])
+    @check_annotator_fails
+    def bad_for_body():
+        f('a')
+
 
 def getgraph(f, argtypes):
     from pypy.translator.translator import TranslationContext, graphof