[pypy-commit] pypy signatures: Add "array" signature type for non-resizable lists
Greg Price
noreply at buildbot.pypy.org
Tue Dec 4 01:21:09 CET 2012
Author: Greg Price <price at mit.edu>
Branch: signatures
Changeset: r59316:303dbf276f7e
Date: 2012-12-02 17:55 -0800
http://bitbucket.org/pypy/pypy/changeset/303dbf276f7e/
Log: Add "array" signature type for non-resizable lists
diff --git a/pypy/annotation/types.py b/pypy/annotation/types.py
--- a/pypy/annotation/types.py
+++ b/pypy/annotation/types.py
@@ -14,3 +14,7 @@
def list(element):
listdef = ListDef(None, element, mutated=True, resized=True)
return model.SomeList(listdef)
+
+def array(element):
+ listdef = ListDef(None, element, mutated=True, resized=False)
+ 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
@@ -566,6 +566,7 @@
assert isinstance(argtype, model.SomeList)
item = argtype.listdef.listitem
assert item.s_value == model.SomeInteger()
+ assert item.resized == True
@check_annotator_fails
def ok_for_body():
@@ -589,6 +590,25 @@
l[0] = 'abc'
return len(l)
+ def can_append():
+ l = ff()
+ l.append('b')
+ getsig(can_append)
+
+def test_signature_array():
+ @signature(returns=types.array(types.int()))
+ def f():
+ return [1]
+ rettype = getsig(f)[0]
+ assert isinstance(rettype, model.SomeList)
+ item = rettype.listdef.listitem
+ assert item.s_value == model.SomeInteger()
+ assert item.resized == False
+
+ def try_append():
+ l = f()
+ l.append(2)
+ check_annotator_fails(try_append)
def getgraph(f, argtypes):
More information about the pypy-commit
mailing list