@@ -216,20 +216,23 @@ def constant_fold_unary_op(op: str, value: ConstantValue) -> int | float | None:
216
216
"builtins.chr" : chr ,
217
217
}
218
218
219
- def constant_fold_call_expr (expr : CallExpr , cur_mod_id : str , foldable_builtins = foldable_builtins ) -> ConstantValue | None :
219
+
220
+ def constant_fold_call_expr (
221
+ expr : CallExpr , cur_mod_id : str , foldable_builtins = foldable_builtins
222
+ ) -> ConstantValue | None :
220
223
callee = expr .callee
221
224
if isinstance (callee , NameExpr ):
222
225
func = foldable_builtins .get (callee .fullname )
223
226
if func is None :
224
227
return None
225
-
228
+
226
229
folded_args = []
227
230
for arg in expr .args :
228
231
val = constant_fold_expr (arg , cur_mod_id )
229
232
if val is None :
230
233
return None
231
234
folded_args .append (arg )
232
-
235
+
233
236
args = []
234
237
kwargs = {}
235
238
for folded_arg , arg_kind , arg_name in zip (folded_args , expr .arg_kinds , expr .arg_names ):
@@ -250,9 +253,8 @@ def constant_fold_call_expr(expr: CallExpr, cur_mod_id: str, foldable_builtins=f
250
253
except :
251
254
return None
252
255
# --- f-string requires partial support for both str.join and str.format ---
253
- elif (
254
- isinstance (callee , MemberExpr )
255
- and isinstance (folded_callee := constant_fold_expr (callee .expr , cur_mod_id ), str )
256
+ elif isinstance (callee , MemberExpr ) and isinstance (
257
+ folded_callee := constant_fold_expr (callee .expr , cur_mod_id ), str
256
258
):
257
259
# --- partial str.join constant folding ---
258
260
if (
@@ -275,4 +277,4 @@ def constant_fold_call_expr(expr: CallExpr, cur_mod_id: str, foldable_builtins=f
275
277
if arg_val is None :
276
278
return None
277
279
folded_args .append (arg_val )
278
- return folded_callee .format (* folded_args )
280
+ return folded_callee .format (* folded_args )
0 commit comments