]> granicus.if.org Git - python/commitdiff
inspect: Fix getcallargs() to fail correctly if more than 3 args are missing.
authorYury Selivanov <yselivanov@sprymix.com>
Thu, 27 Mar 2014 22:42:52 +0000 (18:42 -0400)
committerYury Selivanov <yselivanov@sprymix.com>
Thu, 27 Mar 2014 22:42:52 +0000 (18:42 -0400)
Patch by Jeremiah Lowin. Closes #20817.

Lib/inspect.py
Lib/test/test_inspect.py
Misc/NEWS

index 06057afaf2d8efd98236c5aebd96a7e0d937005c..9f9a600815b72868198c6ee7b1e8ffcc5f9a66fa 100644 (file)
@@ -1125,7 +1125,7 @@ def _missing_arguments(f_name, argnames, pos, values):
     elif missing == 2:
         s = "{} and {}".format(*names)
     else:
-        tail = ", {} and {}".format(names[-2:])
+        tail = ", {} and {}".format(*names[-2:])
         del names[-2:]
         s = ", ".join(names) + tail
     raise TypeError("%s() missing %i required %s argument%s: %s" %
index 20f7217d440348bbddd98bbd3ce415ac977873f3..38367f3ff64299f8828b9bae822abc384d0639f4 100644 (file)
@@ -1214,6 +1214,12 @@ class TestGetcallargsFunctions(unittest.TestCase):
             inspect.getcallargs(f5)
 
 
+        # issue20817:
+        def f6(a, b, c):
+            pass
+        with self.assertRaisesRegex(TypeError, "'a', 'b' and 'c'"):
+            inspect.getcallargs(f6)
+
 class TestGetcallargsMethods(TestGetcallargsFunctions):
 
     def setUp(self):
index c51ad17c5c29cfb944a9da6efc9d34171281190a..10ddd9a4bbe8b74500f55699959e14ed3ef6420d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -86,6 +86,9 @@ Library
 - Issue #20816: Fix inspect.getcallargs() to raise correct TypeError for
   missing keyword-only arguments. Patch by Jeremiah Lowin.
 
+- Issue #20817: Fix inspect.getcallargs() to fail correctly if more
+  than 3 arguments are missing. Patch by Jeremiah Lowin.
+
 Documentation
 -------------