cpython: 3de2e729d0fb (original) (raw)
Mercurial > cpython
changeset 89998:3de2e729d0fb
inspect: Fix getcallargs() to raise correct TypeError ... for missing keyword-only arguments. Patch by Jeremiah Lowin. Closes #20816. [#20816]
Yury Selivanov yselivanov@sprymix.com | |
---|---|
date | Thu, 27 Mar 2014 18:23:03 -0400 |
parents | 3f9a81297b39 |
children | 35302cc4fc93 |
files | Lib/inspect.py Lib/test/test_inspect.py Misc/NEWS |
diffstat | 3 files changed, 12 insertions(+), 1 deletions(-)[+] [-] Lib/inspect.py 2 Lib/test/test_inspect.py 8 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1210,7 +1210,7 @@ def getcallargs(*func_and_positional, ** missing = 0 for kwarg in kwonlyargs: if kwarg not in arg2value:
if kwarg in kwonlydefaults:[](#l1.7)
if kwonlydefaults and kwarg in kwonlydefaults:[](#l1.8) arg2value[kwarg] = kwonlydefaults[kwarg][](#l1.9) else:[](#l1.10) missing += 1[](#l1.11)
--- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -1208,6 +1208,14 @@ class TestGetcallargsFunctions(unittest. self.assertEqualException(f3, '1, 2') self.assertEqualException(f3, '1, 2, a=1, b=2')
# issue #20816: getcallargs() fails to iterate over non-existent[](#l2.7)
# kwonlydefaults and raises a wrong TypeError[](#l2.8)
def f5(*, a): pass[](#l2.9)
with self.assertRaisesRegex(TypeError,[](#l2.10)
'missing 1 required keyword-only'):[](#l2.11)
inspect.getcallargs(f5)[](#l2.12)
+ + class TestGetcallargsMethods(TestGetcallargsFunctions): def setUp(self):