]> 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 fdb5e2a45a2e06310a2025681e6140a36c76b3c3..bb3109883a5945455c1dd49d750f079bfd7cd21c 100644 (file)
@@ -1127,7 +1127,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 b94353031bde3c9a2ffab227b87e93657cc2fb5d..881ca95a7001887ca240d53203b5c704f23d0434 100644 (file)
@@ -1216,6 +1216,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 fa774ba50d9bed4775faeb219029fa2edf30d2dc..3d62992d30cdf81025db6a55b2c0f535e6552f6e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -116,6 +116,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
 -------------