Skip to content

Commit

Permalink
gh-104683: Argument clinic: use dict over OrderedDict (#104647)
Browse files Browse the repository at this point in the history
For code readability. Instances of `builtins.dict` have been ordered since 3.6, and have been guaranteed by the language to be ordered since Python 3.7. Argument Clinic now requires Python 3.10+.
  • Loading branch information
AlexWaygood committed May 20, 2023
1 parent 06eeee9 commit 02b6003
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2060,8 +2060,8 @@ def __init__(self, language, printer=None, *, verify=True, filename=None):
self.printer = printer or BlockPrinter(language)
self.verify = verify
self.filename = filename
self.modules = collections.OrderedDict()
self.classes = collections.OrderedDict()
self.modules = {}
self.classes = {}
self.functions = []

self.line_prefix = self.line_suffix = ''
Expand All @@ -2074,18 +2074,18 @@ def __init__(self, language, printer=None, *, verify=True, filename=None):
self.add_destination("file", "file", "{dirname}/clinic/{basename}.h")

d = self.get_destination_buffer
self.destination_buffers = collections.OrderedDict((
('cpp_if', d('file')),
('docstring_prototype', d('suppress')),
('docstring_definition', d('file')),
('methoddef_define', d('file')),
('impl_prototype', d('file')),
('parser_prototype', d('suppress')),
('parser_definition', d('file')),
('cpp_endif', d('file')),
('methoddef_ifndef', d('file', 1)),
('impl_definition', d('block')),
))
self.destination_buffers = {
'cpp_if': d('file'),
'docstring_prototype': d('suppress'),
'docstring_definition': d('file'),
'methoddef_define': d('file'),
'impl_prototype': d('file'),
'parser_prototype': d('suppress'),
'parser_definition': d('file'),
'cpp_endif': d('file'),
'methoddef_ifndef': d('file', 1),
'impl_definition': d('block'),
}

self.destination_buffers_stack = []
self.ifndef_symbols = set()
Expand All @@ -2098,7 +2098,7 @@ def __init__(self, language, printer=None, *, verify=True, filename=None):
continue
name, value, *options = line.split()
if name == 'preset':
self.presets[value] = preset = collections.OrderedDict()
self.presets[value] = preset = {}
continue

if len(options):
Expand Down Expand Up @@ -2301,8 +2301,8 @@ def __init__(
self.name = name
self.module = self.parent = module

self.modules: ModuleDict = collections.OrderedDict()
self.classes: ClassDict = collections.OrderedDict()
self.modules: ModuleDict = {}
self.classes: ClassDict = {}
self.functions: list[Function] = []

def __repr__(self) -> str:
Expand All @@ -2327,7 +2327,7 @@ def __init__(
self.type_object = type_object
self.parent = cls or module

self.classes: ClassDict = collections.OrderedDict()
self.classes: ClassDict = {}
self.functions: list[Function] = []

def __repr__(self) -> str:
Expand Down Expand Up @@ -2428,7 +2428,7 @@ def __init__(self, parameters=None, *, name,
return_converter, return_annotation=inspect.Signature.empty,
docstring=None, kind=CALLABLE, coexist=False,
docstring_only=False):
self.parameters = parameters or collections.OrderedDict()
self.parameters = parameters or {}
self.return_annotation = return_annotation
self.name = name
self.full_name = full_name
Expand Down Expand Up @@ -2489,12 +2489,10 @@ def copy(self, **overrides):
}
kwargs.update(overrides)
f = Function(**kwargs)

parameters = collections.OrderedDict()
for name, value in f.parameters.items():
value = value.copy(function=f)
parameters[name] = value
f.parameters = parameters
f.parameters = {
name: value.copy(function=f)
for name, value in f.parameters.items()
}
return f


Expand Down

0 comments on commit 02b6003

Please sign in to comment.