[pypy-svn] r61998 - in pypy/trunk/pypy/interpreter: . test

afa at codespeak.net afa at codespeak.net
Wed Feb 18 11:15:35 CET 2009


Author: afa
Date: Wed Feb 18 11:15:35 2009
New Revision: 61998

Modified:
   pypy/trunk/pypy/interpreter/argument.py
   pypy/trunk/pypy/interpreter/test/test_function.py
Log:
When calling a function with the incorrect number of parameters,
don't add the number of "blind" arguments to the error message.
otherwise you get misleading error messages like:

>>>> len()
TypeError: len() takes exactly 1 argument (1 given)


Modified: pypy/trunk/pypy/interpreter/argument.py
==============================================================================
--- pypy/trunk/pypy/interpreter/argument.py	(original)
+++ pypy/trunk/pypy/interpreter/argument.py	Wed Feb 18 11:15:35 2009
@@ -257,11 +257,11 @@
         avail = upfront + self.nargs
         
         if avail + len(defaults_w) < co_argcount:
-            raise ArgErrCount(blindargs + self.nargs , 0,
+            raise ArgErrCount(self.nargs , 0,
                               (co_argcount, has_vararg, has_kwarg),
                               defaults_w, co_argcount - avail - len(defaults_w))
         if avail > co_argcount and not has_vararg:
-            raise ArgErrCount(blindargs + self.nargs, 0,
+            raise ArgErrCount(self.nargs, 0,
                               (co_argcount, has_vararg, has_kwarg),
                               defaults_w, 0)
 

Modified: pypy/trunk/pypy/interpreter/test/test_function.py
==============================================================================
--- pypy/trunk/pypy/interpreter/test/test_function.py	(original)
+++ pypy/trunk/pypy/interpreter/test/test_function.py	Wed Feb 18 11:15:35 2009
@@ -197,6 +197,21 @@
         raises(TypeError, len, s, some_unknown_keyword=s)
         raises(TypeError, len, s, s, some_unknown_keyword=s)
 
+    def test_call_error_message(self):
+        try:
+            len()
+        except TypeError, e:
+            assert "len() takes exactly 1 argument (0 given)" in e.message
+        else:
+            assert 0, "did not raise"
+
+        try:
+            len(1, 2)
+        except TypeError, e:
+            assert "len() takes exactly 1 argument (2 given)" in e.message
+        else:
+            assert 0, "did not raise"
+
     def test_unicode_docstring(self):
         def f():
             u"hi"



More information about the Pypy-commit mailing list