@@ -87,9 +87,8 @@ def __init__(self, declare, behavior, cleanup, sub):
8787 # for that...)
8888 # we need the label even if cleanup is empty because the
8989 # behavior block jumps there on failure
90- self .cleanup = (
91- "__label_%(id)i:\n " % sub + cleanup + "\n double __DUMMY_%(id)i;\n " % sub
92- ) # % sub
90+ id = sub ["id" ]
91+ self .cleanup = f"__label_{ id } :\n { cleanup } \n double __DUMMY_{ id } ;\n "
9392
9493
9594def failure_code (sub , use_goto = True ):
@@ -114,14 +113,16 @@ def failure_code(sub, use_goto=True):
114113 goto_statement = "goto __label_%(id)i;" % sub
115114 else :
116115 goto_statement = ""
117- return """{
118- %(failure_var)s = %(id)i;
119- if (!PyErr_Occurred()) {
116+ id = sub ["id" ]
117+ failure_var = sub ["failure_var" ]
118+ return f"""{{
119+ { failure_var } = { id } ;
120+ if (!PyErr_Occurred()) {{
120121 PyErr_SetString(PyExc_RuntimeError,
121122 "Unexpected error in an Op's C code. "
122123 "No Python exception was set.");
123- }
124- %( goto_statement)s} """ % dict ( sub , goto_statement = goto_statement )
124+ }}
125+ { goto_statement } }} """
125126
126127
127128def failure_code_init (sub ):
@@ -135,17 +136,15 @@ def failure_code_init(sub):
135136 * failure_var -> must contain a variable name to use for
136137 the failure code.
137138 """
138- return (
139- """{
140- if (!PyErr_Occurred()) {
139+ id = sub [ "id" ]
140+ return f """{ {
141+ if (!PyErr_Occurred()) {{
141142 PyErr_SetString(PyExc_RuntimeError,
142143 "Unexpected error in an Op's C code. "
143144 "No Python exception was set.");
144- }
145- return %(id)d;
146- }"""
147- % sub
148- )
145+ }}
146+ return { id } ;
147+ }}"""
149148
150149
151150def code_gen (blocks ):
@@ -1657,10 +1656,9 @@ def instantiate_code(self, n_args):
16571656 file = code ,
16581657 )
16591658 print (" assert(PyTuple_Check(argtuple));" , file = code )
1660- print (" if (%( n_args)i != PyTuple_Size(argtuple)){ " % locals () , file = code )
1659+ print (f " if ({ n_args } != PyTuple_Size(argtuple)){{ " , file = code )
16611660 print (
1662- ' PyErr_Format(PyExc_TypeError, "Wrong number of arguments, expected %(n_args)i, got %%i", (int)PyTuple_Size(argtuple));'
1663- % locals (),
1661+ f' PyErr_Format(PyExc_TypeError, "Wrong number of arguments, expected { n_args } , got %%i", (int)PyTuple_Size(argtuple));' ,
16641662 file = code ,
16651663 )
16661664 print (" return NULL;" , file = code )
0 commit comments