summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorErlend E. Aasland <erlend@python.org>2023-08-28 12:41:05 (GMT)
committerGitHub <noreply@github.com>2023-08-28 12:41:05 (GMT)
commitd90973340bf5ac35e0b35e99239cd37c46a30910 (patch)
tree4a8578d0a4c74d05e70336718a7e14ab4081fd0c /Tools
parent0e8b3fc718c8a1c4de558c553d9e05049c1dbec6 (diff)
downloadcpython-d90973340bf5ac35e0b35e99239cd37c46a30910.zip
cpython-d90973340bf5ac35e0b35e99239cd37c46a30910.tar.gz
cpython-d90973340bf5ac35e0b35e99239cd37c46a30910.tar.bz2
gh-104683: Argument Clinic: Refactor the module and class resolver (#108552)
Diffstat (limited to 'Tools')
-rwxr-xr-xTools/clinic/clinic.py26
1 files changed, 10 insertions, 16 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index 70ec18f..1fb53c3 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -2554,7 +2554,7 @@ impl_definition block
return printer.f.getvalue()
def _module_and_class(
- self, fields: Iterable[str]
+ self, fields: Sequence[str]
) -> tuple[Module | Clinic, Class | None]:
"""
fields should be an iterable of field names.
@@ -2563,26 +2563,20 @@ impl_definition block
this function is only ever used to find the parent of where
a new class/module should go.
"""
- parent: Clinic | Module | Class
- child: Module | Class | None
- module: Clinic | Module
+ parent: Clinic | Module | Class = self
+ module: Clinic | Module = self
cls: Class | None = None
- so_far: list[str] = []
- parent = module = self
-
- for field in fields:
- so_far.append(field)
+ for idx, field in enumerate(fields):
if not isinstance(parent, Class):
- child = parent.modules.get(field)
- if child:
- parent = module = child
+ if field in parent.modules:
+ parent = module = parent.modules[field]
continue
- child = parent.classes.get(field)
- if not child:
- fullname = ".".join(so_far)
+ if field in parent.classes:
+ parent = cls = parent.classes[field]
+ else:
+ fullname = ".".join(fields[idx:])
fail(f"Parent class or module {fullname!r} does not exist.")
- cls = parent = child
return module, cls