diff options
author | Inada Naoki <songofacandy@gmail.com> | 2020-03-02 09:54:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-02 09:54:48 (GMT) |
commit | 211055176157545ce98e6c02b09d624719e6dd30 (patch) | |
tree | a5727a736333dd62017bfcaa5ed57b6c1f2336eb /Lib | |
parent | 9f1cb1bb49476246de5d9ed5fe680301cf7f7571 (diff) | |
download | cpython-211055176157545ce98e6c02b09d624719e6dd30.zip cpython-211055176157545ce98e6c02b09d624719e6dd30.tar.gz cpython-211055176157545ce98e6c02b09d624719e6dd30.tar.bz2 |
bpo-39775: inspect: Change Signature.parameters back to OrderedDict. (GH-18684)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/inspect.py | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 950bdb2..bb82f96 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -48,7 +48,7 @@ import warnings import functools import builtins from operator import attrgetter -from collections import namedtuple +from collections import namedtuple, OrderedDict # Create constants for the compiler flags in Include/code.h # We try to get them from dis to avoid duplication @@ -1727,7 +1727,7 @@ def _signature_get_partial(wrapped_sig, partial, extra_args=()): """ old_params = wrapped_sig.parameters - new_params = {} + new_params = OrderedDict(old_params.items()) partial_args = partial.args or () partial_keywords = partial.keywords or {} @@ -1743,7 +1743,6 @@ def _signature_get_partial(wrapped_sig, partial, extra_args=()): transform_to_kwonly = False - kwonly_params = {} # Keyword only parameters are moved to end. for param_name, param in old_params.items(): try: arg_value = ba.arguments[param_name] @@ -1753,6 +1752,7 @@ def _signature_get_partial(wrapped_sig, partial, extra_args=()): if param.kind is _POSITIONAL_ONLY: # If positional-only parameter is bound by partial, # it effectively disappears from the signature + new_params.pop(param_name) continue if param.kind is _POSITIONAL_OR_KEYWORD: @@ -1771,26 +1771,28 @@ def _signature_get_partial(wrapped_sig, partial, extra_args=()): # multiple values. transform_to_kwonly = True # Set the new default value - param = param.replace(default=arg_value) + new_params[param_name] = param.replace(default=arg_value) else: # was passed as a positional argument + new_params.pop(param.name) continue if param.kind is _KEYWORD_ONLY: # Set the new default value - param = param.replace(default=arg_value) + new_params[param_name] = param.replace(default=arg_value) if transform_to_kwonly: assert param.kind is not _POSITIONAL_ONLY if param.kind is _POSITIONAL_OR_KEYWORD: - kwonly_params[param_name] = param.replace(kind=_KEYWORD_ONLY) + new_param = new_params[param_name].replace(kind=_KEYWORD_ONLY) + new_params[param_name] = new_param + new_params.move_to_end(param_name) elif param.kind in (_KEYWORD_ONLY, _VAR_KEYWORD): - kwonly_params[param_name] = param - else: - new_params[param_name] = param + new_params.move_to_end(param_name) + elif param.kind is _VAR_POSITIONAL: + new_params.pop(param.name) - new_params.update(kwonly_params) return wrapped_sig.replace(parameters=new_params.values()) |