diff options
author | RĂ©mi Lapeyre <remi.lapeyre@henki.fr> | 2020-01-28 12:47:03 (GMT) |
---|---|---|
committer | Inada Naoki <songofacandy@gmail.com> | 2020-01-28 12:47:03 (GMT) |
commit | 2cca8efe46935c39c445f585bce54954fad2485b (patch) | |
tree | f1742035d30478e763ef671189e66fbb64381049 /Lib/inspect.py | |
parent | 0be3246d4f9c8eddcd55491901d95b09fe163f15 (diff) | |
download | cpython-2cca8efe46935c39c445f585bce54954fad2485b.zip cpython-2cca8efe46935c39c445f585bce54954fad2485b.tar.gz cpython-2cca8efe46935c39c445f585bce54954fad2485b.tar.bz2 |
bpo-36350: inspect: Replace OrderedDict with dict. (GH-12412)
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 608ca95..950bdb2 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, OrderedDict +from collections import namedtuple # 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 = OrderedDict(old_params.items()) + new_params = {} partial_args = partial.args or () partial_keywords = partial.keywords or {} @@ -1743,6 +1743,7 @@ 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] @@ -1752,7 +1753,6 @@ 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,28 +1771,26 @@ def _signature_get_partial(wrapped_sig, partial, extra_args=()): # multiple values. transform_to_kwonly = True # Set the new default value - new_params[param_name] = param.replace(default=arg_value) + param = 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 - new_params[param_name] = param.replace(default=arg_value) + param = param.replace(default=arg_value) if transform_to_kwonly: assert param.kind is not _POSITIONAL_ONLY if param.kind is _POSITIONAL_OR_KEYWORD: - new_param = new_params[param_name].replace(kind=_KEYWORD_ONLY) - new_params[param_name] = new_param - new_params.move_to_end(param_name) + kwonly_params[param_name] = param.replace(kind=_KEYWORD_ONLY) elif param.kind in (_KEYWORD_ONLY, _VAR_KEYWORD): - new_params.move_to_end(param_name) - elif param.kind is _VAR_POSITIONAL: - new_params.pop(param.name) + kwonly_params[param_name] = param + else: + new_params[param_name] = param + new_params.update(kwonly_params) return wrapped_sig.replace(parameters=new_params.values()) @@ -2602,7 +2600,7 @@ class BoundArguments: Has the following public attributes: - * arguments : OrderedDict + * arguments : dict An ordered mutable mapping of parameters' names to arguments' values. Does not contain arguments' default values. * signature : Signature @@ -2702,7 +2700,7 @@ class BoundArguments: # Signature.bind_partial(). continue new_arguments.append((name, val)) - self.arguments = OrderedDict(new_arguments) + self.arguments = dict(new_arguments) def __eq__(self, other): if self is other: @@ -2733,7 +2731,7 @@ class Signature: A Signature object has the following public attributes and methods: - * parameters : OrderedDict + * parameters : dict An ordered mapping of parameters' names to the corresponding Parameter objects (keyword-only arguments are in the same order as listed in `code.co_varnames`). @@ -2763,14 +2761,14 @@ class Signature: """ if parameters is None: - params = OrderedDict() + params = {} else: if __validate_parameters__: - params = OrderedDict() + params = {} top_kind = _POSITIONAL_ONLY kind_defaults = False - for idx, param in enumerate(parameters): + for param in parameters: kind = param.kind name = param.name @@ -2805,8 +2803,7 @@ class Signature: params[name] = param else: - params = OrderedDict(((param.name, param) - for param in parameters)) + params = {param.name: param for param in parameters} self._parameters = types.MappingProxyType(params) self._return_annotation = return_annotation @@ -2888,7 +2885,7 @@ class Signature: def _bind(self, args, kwargs, *, partial=False): """Private method. Don't use directly.""" - arguments = OrderedDict() + arguments = {} parameters = iter(self.parameters.values()) parameters_ex = () |