Commits

Manuel Jacob committed 2fb15b5

Print a better error message when too many positional arguments are given.

  • Participants
  • Parent commits 90dd1de
  • Branches py3k

Comments (0)

Files changed (2)

File pypy/interpreter/argument.py

                 plural = "s"
             if has_kwarg or num_kwds > 0:
                 msg2 = " non-keyword"
+            elif defcount != -1: # XXX not sure about this
+                msg2 = " positional"
             else:
                 msg2 = ""
             msg = "takes %s %d%s argument%s (%d given)" % (

File pypy/interpreter/test/test_argument.py

         assert e.value.args[0] == "f() got an unexpected keyword argument 'ü'"
         """
 
+    def test_error_positional(self):
+        """
+        def f(a, b=None, *, c=None):
+            pass
+        exc = raises(TypeError, f, 1, 2, 3)
+        expected = "f() takes at most 2 positional arguments (3 given)"
+        assert str(exc.value) == expected
+        """