[Python-checkins] cpython: inspect: Fix getcallargs() to fail correctly if more than 3 args are missing.

yury.selivanov python-checkins at python.org
Thu Mar 27 23:45:43 CET 2014


http://hg.python.org/cpython/rev/35302cc4fc93
changeset:   90000:35302cc4fc93
parent:      89998:3de2e729d0fb
user:        Yury Selivanov <yselivanov at sprymix.com>
date:        Thu Mar 27 18:42:52 2014 -0400
summary:
  inspect: Fix getcallargs() to fail correctly if more than 3 args are missing.

Patch by Jeremiah Lowin. Closes #20817.

files:
  Lib/inspect.py           |  2 +-
  Lib/test/test_inspect.py |  6 ++++++
  Misc/NEWS                |  3 +++
  3 files changed, 10 insertions(+), 1 deletions(-)


diff --git a/Lib/inspect.py b/Lib/inspect.py
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -1127,7 +1127,7 @@
     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" %
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -1216,6 +1216,12 @@
             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):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -116,6 +116,9 @@
 - 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
 -------------
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list