@@ -87,9 +87,8 @@ def __init__(self, declare, behavior, cleanup, sub):
87
87
# for that...)
88
88
# we need the label even if cleanup is empty because the
89
89
# 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 "
93
92
94
93
95
94
def failure_code (sub , use_goto = True ):
@@ -114,14 +113,16 @@ def failure_code(sub, use_goto=True):
114
113
goto_statement = "goto __label_%(id)i;" % sub
115
114
else :
116
115
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()) {{
120
121
PyErr_SetString(PyExc_RuntimeError,
121
122
"Unexpected error in an Op's C code. "
122
123
"No Python exception was set.");
123
- }
124
- %( goto_statement)s} """ % dict ( sub , goto_statement = goto_statement )
124
+ }}
125
+ { goto_statement } }} """
125
126
126
127
127
128
def failure_code_init (sub ):
@@ -135,17 +136,15 @@ def failure_code_init(sub):
135
136
* failure_var -> must contain a variable name to use for
136
137
the failure code.
137
138
"""
138
- return (
139
- """{
140
- if (!PyErr_Occurred()) {
139
+ id = sub [ "id" ]
140
+ return f """{ {
141
+ if (!PyErr_Occurred()) {{
141
142
PyErr_SetString(PyExc_RuntimeError,
142
143
"Unexpected error in an Op's C code. "
143
144
"No Python exception was set.");
144
- }
145
- return %(id)d;
146
- }"""
147
- % sub
148
- )
145
+ }}
146
+ return { id } ;
147
+ }}"""
149
148
150
149
151
150
def code_gen (blocks ):
@@ -1657,10 +1656,9 @@ def instantiate_code(self, n_args):
1657
1656
file = code ,
1658
1657
)
1659
1658
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 )
1661
1660
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));' ,
1664
1662
file = code ,
1665
1663
)
1666
1664
print (" return NULL;" , file = code )
0 commit comments