Skip to content

gh-104683: Argument clinic: use dict over OrderedDict #104647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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