diff options
author | Yury Selivanov <yselivanov@sprymix.com> | 2014-01-28 22:27:39 (GMT) |
---|---|---|
committer | Yury Selivanov <yselivanov@sprymix.com> | 2014-01-28 22:27:39 (GMT) |
commit | 38b0d5a778c8e296374bd59e6f8bb840d317d6e0 (patch) | |
tree | 52f14a96913db8506530cd57cf0963b697302d27 /Lib/inspect.py | |
parent | 8757ead38e5a05f8525c859ff8c974dba2e290b7 (diff) | |
download | cpython-38b0d5a778c8e296374bd59e6f8bb840d317d6e0.zip cpython-38b0d5a778c8e296374bd59e6f8bb840d317d6e0.tar.gz cpython-38b0d5a778c8e296374bd59e6f8bb840d317d6e0.tar.bz2 |
inspect.Signature.bind: Fix pos-only params with defaults; fix *args in named args #19140
Initial patch by Yann Kaiser (epsy).
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 0e41626..c3fecb8 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -2258,6 +2258,8 @@ class Signature: parameters_ex = (param,) break else: + # No default, not VAR_KEYWORD, not VAR_POSITIONAL, + # not in `kwargs` if partial: parameters_ex = (param,) break @@ -2296,19 +2298,17 @@ class Signature: # keyword arguments kwargs_param = None for param in itertools.chain(parameters_ex, parameters): - if param.kind == _POSITIONAL_ONLY: - # This should never happen in case of a properly built - # Signature object (but let's have this check here - # to ensure correct behaviour just in case) - raise TypeError('{arg!r} parameter is positional only, ' - 'but was passed as a keyword'. \ - format(arg=param.name)) - if param.kind == _VAR_KEYWORD: # Memorize that we have a '**kwargs'-like parameter kwargs_param = param continue + if param.kind == _VAR_POSITIONAL: + # Named arguments don't refer to '*args'-like parameters. + # We only arrive here if the positional arguments ended + # before reaching the last parameter before *args. + continue + param_name = param.name try: arg_val = kwargs.pop(param_name) |