From 2542b66bb04e5634410205f54523987dce9e5bf7 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Thu, 27 Mar 2014 18:42:52 -0400 Subject: [PATCH] inspect: Fix getcallargs() to fail correctly if more than 3 args are missing. Patch by Jeremiah Lowin. Closes #20817. --- Lib/inspect.py | 2 +- Lib/test/test_inspect.py | 6 ++++++ Misc/NEWS | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index 06057afaf2..9f9a600815 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -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" % diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 20f7217d44..38367f3ff6 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -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): diff --git a/Misc/NEWS b/Misc/NEWS index c51ad17c5c..10ddd9a4bb 100644 --- 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 ------------- -- 2.40.0