@@ -176,6 +176,13 @@ def rstrip_lines(s):
176176 text .pop ()
177177 return output ()
178178
179+ def format_escape (s ):
180+ # double up curly-braces, this string will be used
181+ # as part of a format_map() template later
182+ s = s .replace ('{' , '{{' )
183+ s = s .replace ('}' , '}}' )
184+ return s
185+
179186def linear_format (s , ** kwargs ):
180187 """
181188 Perform str.format-like substitution, except:
@@ -996,7 +1003,7 @@ def render_option_group_parsing(self, f, template_dict):
9961003 count_min = sys .maxsize
9971004 count_max = - 1
9981005
999- add ("switch (PyTuple_GET_SIZE(args)) {{ \n " )
1006+ add ("switch (PyTuple_GET_SIZE(args)) {\n " )
10001007 for subset in permute_optional_groups (left , required , right ):
10011008 count = len (subset )
10021009 count_min = min (count_min , count )
@@ -1012,7 +1019,6 @@ def render_option_group_parsing(self, f, template_dict):
10121019 d = {}
10131020 d ['count' ] = count
10141021 d ['name' ] = f .name
1015- d ['groups' ] = sorted (group_ids )
10161022 d ['format_units' ] = "" .join (p .converter .format_unit for p in subset )
10171023
10181024 parse_arguments = []
@@ -1039,8 +1045,8 @@ def render_option_group_parsing(self, f, template_dict):
10391045 s = ' PyErr_SetString(PyExc_TypeError, "{} requires {} to {} arguments");\n '
10401046 add (s .format (f .full_name , count_min , count_max ))
10411047 add (' goto exit;\n ' )
1042- add ("}} " )
1043- template_dict ['option_group_parsing' ] = output ()
1048+ add ("}" )
1049+ template_dict ['option_group_parsing' ] = format_escape ( output () )
10441050
10451051 def render_function (self , clinic , f ):
10461052 if not f :
@@ -1135,16 +1141,16 @@ def render_function(self, clinic, f):
11351141 f .return_converter .render (f , data )
11361142 template_dict ['impl_return_type' ] = f .return_converter .type
11371143
1138- template_dict ['declarations' ] = "\n " .join (data .declarations )
1144+ template_dict ['declarations' ] = format_escape ( "\n " .join (data .declarations ) )
11391145 template_dict ['initializers' ] = "\n \n " .join (data .initializers )
11401146 template_dict ['modifications' ] = '\n \n ' .join (data .modifications )
11411147 template_dict ['keywords' ] = '"' + '", "' .join (data .keywords ) + '"'
11421148 template_dict ['format_units' ] = '' .join (data .format_units )
11431149 template_dict ['parse_arguments' ] = ', ' .join (data .parse_arguments )
11441150 template_dict ['impl_parameters' ] = ", " .join (data .impl_parameters )
11451151 template_dict ['impl_arguments' ] = ", " .join (data .impl_arguments )
1146- template_dict ['return_conversion' ] = "" .join (data .return_conversion ).rstrip ()
1147- template_dict ['cleanup' ] = "" .join (data .cleanup )
1152+ template_dict ['return_conversion' ] = format_escape ( "" .join (data .return_conversion ).rstrip () )
1153+ template_dict ['cleanup' ] = format_escape ( "" .join (data .cleanup ) )
11481154 template_dict ['return_value' ] = data .return_value
11491155
11501156 # used by unpack tuple code generator
@@ -2439,12 +2445,7 @@ def declaration(self):
24392445 declaration .append ('\n Py_ssize_clean_t ' )
24402446 declaration .append (self .length_name ())
24412447 declaration .append (';' )
2442- s = "" .join (declaration )
2443- # double up curly-braces, this string will be used
2444- # as part of a format_map() template later
2445- s = s .replace ("{" , "{{" )
2446- s = s .replace ("}" , "}}" )
2447- return s
2448+ return "" .join (declaration )
24482449
24492450 def initialize (self ):
24502451 """
0 commit comments