diff options
author | Alex Waygood <Alex.Waygood@Gmail.com> | 2023-07-27 21:51:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-27 21:51:18 (GMT) |
commit | c2b1689abcfa80ad959862168b5260fbbd478484 (patch) | |
tree | ca1369ee673096abea930eab1914684d060809dd /Tools/clinic | |
parent | 2f9bb77764c3b41867f79d6df6e2ed71715dad63 (diff) | |
download | cpython-c2b1689abcfa80ad959862168b5260fbbd478484.zip cpython-c2b1689abcfa80ad959862168b5260fbbd478484.tar.gz cpython-c2b1689abcfa80ad959862168b5260fbbd478484.tar.bz2 |
gh-104683: Argument clinic: cleanup `state_modulename_name()` (#107340)
Diffstat (limited to 'Tools/clinic')
-rwxr-xr-x | Tools/clinic/clinic.py | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 5d3ed41..a343dc5 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -4730,6 +4730,7 @@ class DSLParser: return line, _, returns = line.partition('->') + returns = returns.strip() full_name, _, c_basename = line.partition(' as ') full_name = full_name.strip() @@ -4743,23 +4744,21 @@ class DSLParser: return_converter = None if returns: ast_input = f"def x() -> {returns}: pass" - module = None try: - module = ast.parse(ast_input) + module_node = ast.parse(ast_input) except SyntaxError: - pass - if not module: - fail("Badly-formed annotation for " + full_name + ": " + returns) + fail(f"Badly formed annotation for {full_name}: {returns!r}") + function_node = module_node.body[0] + assert isinstance(function_node, ast.FunctionDef) try: - name, legacy, kwargs = self.parse_converter(module.body[0].returns) + name, legacy, kwargs = self.parse_converter(function_node.returns) if legacy: - fail("Legacy converter {!r} not allowed as a return converter" - .format(name)) + fail(f"Legacy converter {name!r} not allowed as a return converter") if name not in return_converters: - fail("No available return converter called " + repr(name)) + fail(f"No available return converter called {name!r}") return_converter = return_converters[name](**kwargs) except ValueError: - fail("Badly-formed annotation for " + full_name + ": " + returns) + fail(f"Badly formed annotation for {full_name}: {returns!r}") fields = [x.strip() for x in full_name.split('.')] function_name = fields.pop() |