Author: Greg Price <[email protected]>
Branch: signatures
Changeset: r59312:0e521e989742
Date: 2012-12-02 17:04 -0800
http://bitbucket.org/pypy/pypy/changeset/0e521e989742/
Log: Basic support for list types in signatures
diff --git a/pypy/annotation/types.py b/pypy/annotation/types.py
--- a/pypy/annotation/types.py
+++ b/pypy/annotation/types.py
@@ -1,4 +1,5 @@
from pypy.annotation import model
+from pypy.annotation.listdef import ListDef
def int():
@@ -6,3 +7,7 @@
def str():
return model.SomeString()
+
+def list(element):
+ listdef = ListDef(None, element, mutated=True, resized=True)
+ return model.SomeList(listdef)
diff --git a/pypy/rlib/test/test_objectmodel.py
b/pypy/rlib/test/test_objectmodel.py
--- a/pypy/rlib/test/test_objectmodel.py
+++ b/pypy/rlib/test/test_objectmodel.py
@@ -556,6 +556,22 @@
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
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit