Anonymous avatar Anonymous committed 303dbf2 Draft

Add "array" signature type for non-resizable lists

Comments (0)

Files changed (2)

pypy/annotation/types.py

 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)

pypy/rlib/test/test_objectmodel.py

     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():
         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):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.