Skip to content

Commit 2d43bee

Browse files
gh-104050: Argument Clinic: Annotate nested function parser_body() in the CLanguage class (#106699)
1 parent 8aa4bea commit 2d43bee

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

Tools/clinic/clinic.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -898,22 +898,24 @@ def output_templates(self, f):
898898
# parser_body_fields remembers the fields passed in to the
899899
# previous call to parser_body. this is used for an awful hack.
900900
parser_body_fields = ()
901-
def parser_body(prototype, *fields, declarations=''):
901+
def parser_body(
902+
prototype: str,
903+
*fields: str,
904+
declarations: str = ''
905+
) -> str:
902906
nonlocal parser_body_fields
903907
add, output = text_accumulator()
904908
add(prototype)
905909
parser_body_fields = fields
906910

907-
fields = list(fields)
908-
fields.insert(0, normalize_snippet("""
911+
preamble = normalize_snippet("""
909912
{{
910913
{return_value_declaration}
911914
{parser_declarations}
912915
{declarations}
913916
{initializers}
914-
""") + "\n")
915-
# just imagine--your code is here in the middle
916-
fields.append(normalize_snippet("""
917+
""") + "\n"
918+
finale = normalize_snippet("""
917919
{modifications}
918920
{return_value} = {c_basename}_impl({impl_arguments});
919921
{return_conversion}
@@ -923,8 +925,8 @@ def parser_body(prototype, *fields, declarations=''):
923925
{cleanup}
924926
return return_value;
925927
}}
926-
"""))
927-
for field in fields:
928+
""")
929+
for field in preamble, *fields, finale:
928930
add('\n')
929931
add(field)
930932
return linear_format(output(), parser_declarations=declarations)

0 commit comments

Comments
 (0)