summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-03-28 22:32:31 (GMT)
committerBenjamin Peterson <benjamin@python.org>2011-03-28 22:32:31 (GMT)
commit77d466079a53830e5358c5ee5fe1dd4cda40164c (patch)
tree2ea50dfe502ca07dd4ab9226ff89a1f157e446f5 /Lib/inspect.py
parent41a9ec90030ad29fadba44eb44cc002d1c2cb153 (diff)
downloadcpython-77d466079a53830e5358c5ee5fe1dd4cda40164c.zip
cpython-77d466079a53830e5358c5ee5fe1dd4cda40164c.tar.gz
cpython-77d466079a53830e5358c5ee5fe1dd4cda40164c.tar.bz2
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.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 33065f5..b0b2d3a 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -943,8 +943,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:
+ if num_pos:
+ # XXX: We should use num_pos, but Python also uses num_total:
+ raise TypeError('%s() takes exactly 0 arguments '
+ '(%d given)' % (f_name, num_total))
+ else:
+ raise TypeError('%s() takes no arguments (%d given)' %
+ (f_name, num_total))
for arg in args:
if isinstance(arg, str) and arg in named:
if is_assigned(arg):