(original) (raw)
changeset: 89998:3de2e729d0fb parent: 89996:3f9a81297b39 user: Yury Selivanov yselivanov@sprymix.com date: Thu Mar 27 18:23:03 2014 -0400 files: Lib/inspect.py Lib/test/test_inspect.py Misc/NEWS description: inspect: Fix getcallargs() to raise correct TypeError ... for missing keyword-only arguments. Patch by Jeremiah Lowin. Closes #20816. diff -r 3f9a81297b39 -r 3de2e729d0fb Lib/inspect.py --- a/Lib/inspect.py Thu Mar 27 12:41:53 2014 -0400 +++ b/Lib/inspect.py Thu Mar 27 18:23:03 2014 -0400 @@ -1210,7 +1210,7 @@ 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 -r 3f9a81297b39 -r 3de2e729d0fb Lib/test/test_inspect.py --- a/Lib/test/test_inspect.py Thu Mar 27 12:41:53 2014 -0400 +++ b/Lib/test/test_inspect.py Thu Mar 27 18:23:03 2014 -0400 @@ -1208,6 +1208,14 @@ 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 -r 3f9a81297b39 -r 3de2e729d0fb Misc/NEWS --- a/Misc/NEWS Thu Mar 27 12:41:53 2014 -0400 +++ b/Misc/NEWS Thu Mar 27 18:23:03 2014 -0400 @@ -113,6 +113,9 @@ - Issue #20378: Improve repr of inspect.Signature and inspect.Parameter. +- Issue #20816: Fix inspect.getcallargs() to raise correct TypeError for + missing keyword-only arguments. Patch by Jeremiah Lowin. + Documentation ------------- /yselivanov@sprymix.com