diff options
author | Erlend E. Aasland <erlend@python.org> | 2023-07-12 22:49:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-12 22:49:30 (GMT) |
commit | 2d43beec225a0495ffa0344f961b99717e5f1106 (patch) | |
tree | 06bf06f00d59e9dc5ba22dacef1d115a29dd873d | |
parent | 8aa4beaad0d95917b1bb12d146bc15c1aa815e08 (diff) | |
download | cpython-2d43beec225a0495ffa0344f961b99717e5f1106.zip cpython-2d43beec225a0495ffa0344f961b99717e5f1106.tar.gz cpython-2d43beec225a0495ffa0344f961b99717e5f1106.tar.bz2 |
gh-104050: Argument Clinic: Annotate nested function parser_body() in the CLanguage class (#106699)
-rwxr-xr-x | Tools/clinic/clinic.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index ce3039c..8a75aba 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -898,22 +898,24 @@ class CLanguage(Language): # parser_body_fields remembers the fields passed in to the # previous call to parser_body. this is used for an awful hack. parser_body_fields = () - def parser_body(prototype, *fields, declarations=''): + def parser_body( + prototype: str, + *fields: str, + declarations: str = '' + ) -> str: nonlocal parser_body_fields add, output = text_accumulator() add(prototype) parser_body_fields = fields - fields = list(fields) - fields.insert(0, normalize_snippet(""" + preamble = normalize_snippet(""" {{ {return_value_declaration} {parser_declarations} {declarations} {initializers} - """) + "\n") - # just imagine--your code is here in the middle - fields.append(normalize_snippet(""" + """) + "\n" + finale = normalize_snippet(""" {modifications} {return_value} = {c_basename}_impl({impl_arguments}); {return_conversion} @@ -923,8 +925,8 @@ class CLanguage(Language): {cleanup} return return_value; }} - """)) - for field in fields: + """) + for field in preamble, *fields, finale: add('\n') add(field) return linear_format(output(), parser_declarations=declarations) |