summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2014-03-27 22:23:03 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2014-03-27 22:23:03 (GMT)
commitb1d060bf8b017d2a6cf6a0191b1451aeb27a5c03 (patch)
treee19a16da6d5952ecc45403722cc6f3d751320a8b
parent00abf385ac3b4b13aee66cbeb2a33604d8a871f5 (diff)
downloadcpython-b1d060bf8b017d2a6cf6a0191b1451aeb27a5c03.zip
cpython-b1d060bf8b017d2a6cf6a0191b1451aeb27a5c03.tar.gz
cpython-b1d060bf8b017d2a6cf6a0191b1451aeb27a5c03.tar.bz2
inspect: Fix getcallargs() to raise correct TypeError
... for missing keyword-only arguments. Patch by Jeremiah Lowin. Closes #20816.
-rw-r--r--Lib/inspect.py2
-rw-r--r--Lib/test/test_inspect.py8
-rw-r--r--Misc/NEWS3
3 files changed, 12 insertions, 1 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index c7a2cf8..06057af 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -1208,7 +1208,7 @@ def getcallargs(*func_and_positional, **named):
missing = 0
for kwarg in kwonlyargs:
if kwarg not in arg2value:
- if kwarg in kwonlydefaults:
+ if kwonlydefaults and kwarg in kwonlydefaults:
arg2value[kwarg] = kwonlydefaults[kwarg]
else:
missing += 1
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index 5c6ae39..20f7217 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -1206,6 +1206,14 @@ class TestGetcallargsFunctions(unittest.TestCase):
self.assertEqualException(f3, '1, 2')
self.assertEqualException(f3, '1, 2, a=1, b=2')
+ # issue #20816: getcallargs() fails to iterate over non-existent
+ # kwonlydefaults and raises a wrong TypeError
+ def f5(*, a): pass
+ with self.assertRaisesRegex(TypeError,
+ 'missing 1 required keyword-only'):
+ inspect.getcallargs(f5)
+
+
class TestGetcallargsMethods(TestGetcallargsFunctions):
def setUp(self):
diff --git a/Misc/NEWS b/Misc/NEWS
index 8f55c63..c51ad17 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -83,6 +83,9 @@ Library
- Issue #19748: On AIX, time.mktime() now raises an OverflowError for year
outsize range [1902; 2037].
+- Issue #20816: Fix inspect.getcallargs() to raise correct TypeError for
+ missing keyword-only arguments. Patch by Jeremiah Lowin.
+
Documentation
-------------