Author: Greg Price <[email protected]>
Branch: signatures
Changeset: r59325:27a3d71fe8ec
Date: 2012-12-03 21:23 -0800
http://bitbucket.org/pypy/pypy/changeset/27a3d71fe8ec/
Log: Basic support for dict 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,5 +1,6 @@
from pypy.annotation import model
from pypy.annotation.listdef import ListDef
+from pypy.annotation.dictdef import DictDef
def none():
@@ -38,6 +39,10 @@
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_))
diff --git a/pypy/rlib/test/test_signature.py b/pypy/rlib/test/test_signature.py
--- a/pypy/rlib/test/test_signature.py
+++ b/pypy/rlib/test/test_signature.py
@@ -147,6 +147,15 @@
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):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit