summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-05-19 04:27:49 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2015-05-19 04:27:49 (GMT)
commit8687275358a9267c5ea7dcd4ce6a4cbd0f91f541 (patch)
tree7d93ab90e1f03c10dd6df80933bbace0b7a155ff /Lib/inspect.py
parentfee05daef8b9e0e0977e413260009ebf54bf4486 (diff)
downloadcpython-8687275358a9267c5ea7dcd4ce6a4cbd0f91f541.zip
cpython-8687275358a9267c5ea7dcd4ce6a4cbd0f91f541.tar.gz
cpython-8687275358a9267c5ea7dcd4ce6a4cbd0f91f541.tar.bz2
Issue 24205: Improve inspect.Signature.bind() error messages.
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 8d2920a..13d0c7b 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -2762,7 +2762,7 @@ class Signature:
parameters_ex = (param,)
break
else:
- msg = '{arg!r} parameter lacking default value'
+ msg = 'missing a required argument: {arg!r}'
msg = msg.format(arg=param.name)
raise TypeError(msg) from None
else:
@@ -2775,7 +2775,8 @@ class Signature:
if param.kind in (_VAR_KEYWORD, _KEYWORD_ONLY):
# Looks like we have no parameter for this positional
# argument
- raise TypeError('too many positional arguments')
+ raise TypeError(
+ 'too many positional arguments') from None
if param.kind == _VAR_POSITIONAL:
# We have an '*args'-like argument, let's fill it with
@@ -2787,8 +2788,9 @@ class Signature:
break
if param.name in kwargs:
- raise TypeError('multiple values for argument '
- '{arg!r}'.format(arg=param.name))
+ raise TypeError(
+ 'multiple values for argument {arg!r}'.format(
+ arg=param.name)) from None
arguments[param.name] = arg_val
@@ -2817,7 +2819,7 @@ class Signature:
# arguments.
if (not partial and param.kind != _VAR_POSITIONAL and
param.default is _empty):
- raise TypeError('{arg!r} parameter lacking default value'. \
+ raise TypeError('missing a required argument: {arg!r}'. \
format(arg=param_name)) from None
else:
@@ -2836,7 +2838,9 @@ class Signature:
# Process our '**kwargs'-like parameter
arguments[kwargs_param.name] = kwargs
else:
- raise TypeError('too many keyword arguments')
+ raise TypeError(
+ 'got an unexpected keyword argument {arg!r}'.format(
+ arg=next(iter(kwargs))))
return self._bound_arguments_cls(self, arguments)