Commits

Greg Price  committed 27a3d71

Basic support for dict types in signatures

  • Participants
  • Parent commits f731001
  • Branches signatures

Comments (0)

Files changed (2)

File 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_))

File 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):