[pypy-commit] pypy default: (price, fijal) signature: stubs and failing tests for class signatures

Greg Price noreply at buildbot.pypy.org
Mon Mar 25 07:37:43 CET 2013


Author: Greg Price <price at mit.edu>
Branch: 
Changeset: r62728:896726ddd842
Date: 2013-03-24 22:36 -0700
http://bitbucket.org/pypy/pypy/changeset/896726ddd842/

Log:	(price, fijal) signature: stubs and failing tests for class
	signatures

diff --git a/rpython/rlib/signature.py b/rpython/rlib/signature.py
--- a/rpython/rlib/signature.py
+++ b/rpython/rlib/signature.py
@@ -38,3 +38,13 @@
             paramtypes, returntype = attr._signature_
             attr._signature_ = (tuple(fix(t) for t in paramtypes), fix(returntype))
     return cls
+
+
+class FieldSpec(object):
+    def __init__(self, tp):
+        pass
+
+
+class ClassSpec(object):
+    def __init__(self, fields, inherit=False):
+        pass
diff --git a/rpython/rlib/test/test_signature.py b/rpython/rlib/test/test_signature.py
--- a/rpython/rlib/test/test_signature.py
+++ b/rpython/rlib/test/test_signature.py
@@ -1,5 +1,5 @@
 import py
-from rpython.rlib.signature import signature, finishsigs
+from rpython.rlib.signature import signature, finishsigs, FieldSpec, ClassSpec
 from rpython.rlib import types
 from rpython.annotator import model
 from rpython.translator.translator import TranslationContext, graphof
@@ -284,3 +284,64 @@
     exc = py.test.raises(Exception, annotate_at, cannot_add_string).value
     assert 'Blocked block' in repr(exc.args)
     assert 'cannot_add_string' in repr(exc.args)
+
+
+
+ at py.test.mark.xfail
+def test_class_basic():
+    class C(object):
+        _fields_ = ClassSpec({'x': FieldSpec(types.int)})
+
+    def wrong_type():
+        c = C()
+        c.x = 'a'
+    check_annotator_fails(wrong_type)
+
+    def bad_field():
+        c = C()
+        c.y = 3
+    check_annotator_fails(bad_field)
+
+
+ at py.test.mark.xfail
+def test_class_shorthand():
+    class C1(object):
+        _fields_ = {'x': FieldSpec(types.int)}
+    def wrong_type_1():
+        c = C1()
+        c.x = 'a'
+    check_annotator_fails(wrong_type_1)
+
+    class C2(object):
+        _fields_ = ClassSpec({'x': types.int})
+    def wrong_type_2():
+        c = C2()
+        c.x = 'a'
+    check_annotator_fails(wrong_type_1)
+
+
+ at py.test.mark.xfail
+def test_class_inherit():
+    class C(object):
+        _fields_ = ClassSpec({'x': FieldSpec(types.int)})
+
+    class C1(object):
+        _fields_ = ClassSpec({'y': FieldSpec(types.int)})
+
+    class C2(object):
+        _fields_ = ClassSpec({'y': FieldSpec(types.int)}, inherit=True)
+
+    def no_inherit():
+        c = C1()
+        c.x = 3
+    check_annotator_fails(no_inherit)
+
+    def good():
+        c = C2()
+        c.x = 3
+    annotate_at(good)
+
+    def wrong_type():
+        c = C2()
+        c.x = 'a'
+    check_annotator_fails(wrong_type)


More information about the pypy-commit mailing list