From 0ec1f1accae0a79bc5ff8a0651ff1f7d97b6b121 Mon Sep 17 00:00:00 2001 From: Srinivas Reddy Thatiparthy Date: Sun, 24 Dec 2017 03:27:15 +0530 Subject: [PATCH 1/2] Convert OrderedDict to dict --- Lib/inspect.py | 24 +++++++++---------- .../2017-12-24-03-29-37.bpo-32360.eZe-ID.rst | 1 + 2 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 Misc/NEWS.d/next/Documentation/2017-12-24-03-29-37.bpo-32360.eZe-ID.rst diff --git a/Lib/inspect.py b/Lib/inspect.py index b7551878b74994..5a7665fbac8b23 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -49,7 +49,7 @@ 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 @@ -1709,7 +1709,7 @@ def _signature_get_partial(wrapped_sig, partial, extra_args=()): """ old_params = wrapped_sig.parameters - new_params = OrderedDict(old_params.items()) + new_params = dict(old_params.items()) partial_args = partial.args or () partial_keywords = partial.keywords or {} @@ -1768,10 +1768,10 @@ def _signature_get_partial(wrapped_sig, partial, extra_args=()): if param.kind is _POSITIONAL_OR_KEYWORD: new_param = new_params[param_name].replace(kind=_KEYWORD_ONLY) + del new_params[param_name] new_params[param_name] = new_param - new_params.move_to_end(param_name) elif param.kind in (_KEYWORD_ONLY, _VAR_KEYWORD): - new_params.move_to_end(param_name) + new_params[param_name] = new_params.pop(param_name) elif param.kind is _VAR_POSITIONAL: new_params.pop(param.name) @@ -2560,7 +2560,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 @@ -2660,7 +2660,7 @@ def apply_defaults(self): # 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: @@ -2691,7 +2691,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`). @@ -2721,10 +2721,10 @@ def __init__(self, parameters=None, *, return_annotation=_empty, """ if parameters is None: - params = OrderedDict() + params = {} else: if __validate_parameters__: - params = OrderedDict() + params = {} top_kind = _POSITIONAL_ONLY kind_defaults = False @@ -2759,8 +2759,8 @@ def __init__(self, parameters=None, *, return_annotation=_empty, params[name] = param else: - params = OrderedDict(((param.name, param) - for param in parameters)) + params = dict(((param.name, param) + for param in parameters)) self._parameters = types.MappingProxyType(params) self._return_annotation = return_annotation @@ -2836,7 +2836,7 @@ def __eq__(self, other): def _bind(self, args, kwargs, *, partial=False): """Private method. Don't use directly.""" - arguments = OrderedDict() + arguments = {} parameters = iter(self.parameters.values()) parameters_ex = () diff --git a/Misc/NEWS.d/next/Documentation/2017-12-24-03-29-37.bpo-32360.eZe-ID.rst b/Misc/NEWS.d/next/Documentation/2017-12-24-03-29-37.bpo-32360.eZe-ID.rst new file mode 100644 index 00000000000000..4b61457d44e020 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2017-12-24-03-29-37.bpo-32360.eZe-ID.rst @@ -0,0 +1 @@ +Remove references of OrderedDict in the module `inspect` From 220e754f5a6a4efa7d4e28c951702a83616e2519 Mon Sep 17 00:00:00 2001 From: Srinivas Reddy Thatiparthy Date: Thu, 25 Jan 2018 00:06:33 +0530 Subject: [PATCH 2/2] Address review comments --- Lib/inspect.py | 7 +++---- .../Documentation/2017-12-24-03-29-37.bpo-32360.eZe-ID.rst | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index 5a7665fbac8b23..2d0977b7d10acf 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -49,7 +49,7 @@ 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 @@ -1771,7 +1771,7 @@ def _signature_get_partial(wrapped_sig, partial, extra_args=()): del new_params[param_name] new_params[param_name] = new_param elif param.kind in (_KEYWORD_ONLY, _VAR_KEYWORD): - new_params[param_name] = new_params.pop(param_name) + new_params[param_name] = new_params.pop(param_name) # move `param_name` to an end elif param.kind is _VAR_POSITIONAL: new_params.pop(param.name) @@ -2759,8 +2759,7 @@ def __init__(self, parameters=None, *, return_annotation=_empty, params[name] = param else: - params = dict(((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 diff --git a/Misc/NEWS.d/next/Documentation/2017-12-24-03-29-37.bpo-32360.eZe-ID.rst b/Misc/NEWS.d/next/Documentation/2017-12-24-03-29-37.bpo-32360.eZe-ID.rst index 4b61457d44e020..ba5b4e2d90ad90 100644 --- a/Misc/NEWS.d/next/Documentation/2017-12-24-03-29-37.bpo-32360.eZe-ID.rst +++ b/Misc/NEWS.d/next/Documentation/2017-12-24-03-29-37.bpo-32360.eZe-ID.rst @@ -1 +1 @@ -Remove references of OrderedDict in the module `inspect` +Remove imports of OrderedDict in the module `inspect`