Commits

Greg Price  committed 8b134bc

signatures: better check on return types (but still incomplete)

The xfail test demonstrates a known limitation of this error check.

  • Participants
  • Parent commits f53b6d3

Comments (0)

Files changed (2)

File pypy/annotation/signature.py

     actualtypes[:] = params_s
 
 def enforce_signature_return(funcdesc, sigtype, inferredtype):
-    return finish_type(sigtype, funcdesc.bookkeeper, funcdesc.pyobj)
+    s_sigret = finish_type(sigtype, funcdesc.bookkeeper, funcdesc.pyobj)
+    if not s_sigret.contains(inferredtype):
+        raise Exception("%r return value:\n"
+                        "expected %s,\n"
+                        "     got %s" % (funcdesc, s_sigret, inferredtype))
+    return s_sigret

File pypy/rlib/test/test_signature.py

     @signature(returns=types.int())
     def int_not_char():
         return 'a'
+
     @check_annotator_fails
     @signature(types.str(), returns=types.int())
     def str_to_int(s):
         return s
 
+    @signature(returns=types.str())
+    def str_not_None():
+        return None
+    @check_annotator_fails
+    def caller_of_str_not_None():
+        return str_not_None()
+
+@py.test.mark.xfail
+def test_return_errors_xfail():
+    @check_annotator_fails
+    @signature(returns=types.str())
+    def str_not_None():
+        return None
+
 
 def test_none():
     @signature(returns=types.none())