diff options
author | Benjamin Peterson <benjamin@python.org> | 2011-03-28 17:32:31 -0500 |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2011-03-28 17:32:31 -0500 |
commit | 6a2638b1637bd7f79f55def97df20cfccff02509 (patch) | |
tree | 3a45b015ff2be6a0a91f3ce19b69b66279bebad5 /Lib/inspect.py | |
parent | 3077404de4ce8efe5214f4dbf973421eebdf1181 (diff) | |
download | cpython-git-6a2638b1637bd7f79f55def97df20cfccff02509.tar.gz |
Correct handling of functions with only kwarg args in getcallargs (closes #11256)
A patch from Daniel Urban.
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index aa951d83e2..4899cbf9f0 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -944,8 +944,14 @@ def getcallargs(func, *positional, **named): f_name, 'at most' if defaults else 'exactly', num_args, 'arguments' if num_args > 1 else 'argument', num_total)) elif num_args == 0 and num_total: - raise TypeError('%s() takes no arguments (%d given)' % - (f_name, num_total)) + if varkw or kwonlyargs: + if num_pos: + # XXX: We should use num_pos, but Python also uses num_total: + raise TypeError('%s() takes exactly 0 positional arguments ' + '(%d given)' % (f_name, num_total)) + else: + raise TypeError('%s() takes no arguments (%d given)' % + (f_name, num_total)) for arg in itertools.chain(args, kwonlyargs): if arg in named: |