Anonymous avatar Anonymous committed 27a3d71

Basic support for dict types in signatures

Comments (0)

Files changed (2)

pypy/annotation/types.py

 from pypy.annotation import model
 from pypy.annotation.listdef import ListDef
+from pypy.annotation.dictdef import DictDef
 
 
 def none():
     listdef = ListDef(None, element, mutated=True, resized=False)
     return model.SomeList(listdef)
 
+def dict(keytype, valuetype):
+    dictdef = DictDef(None, keytype, valuetype)
+    return model.SomeDict(dictdef)
+
 
 def instance(class_):
     return lambda bookkeeper: model.SomeInstance(bookkeeper.getuniqueclassdef(class_))

pypy/rlib/test/test_signature.py

         l.append(2)
     check_annotator_fails(try_append)
 
+def test_signature_dict():
+    @signature(returns=types.dict(types.str(), types.int()))
+    def f():
+        return {'a': 1, 'b': 2}
+    rettype = getsig(f)[0]
+    assert isinstance(rettype, model.SomeDict)
+    assert rettype.dictdef.dictkey.s_value   == model.SomeString()
+    assert rettype.dictdef.dictvalue.s_value == model.SomeInteger()
+
 
 def test_signature_instance():
     class C1(object):
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.