Anonymous avatar Anonymous committed 8b134bc

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

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

Comments (0)

Files changed (2)


     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


     def int_not_char():
         return 'a'
     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()
+def test_return_errors_xfail():
+    @check_annotator_fails
+    @signature(returns=types.str())
+    def str_not_None():
+        return None
 def test_none():
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
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.