File tree Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Original file line number Diff line number Diff line change @@ -446,21 +446,22 @@ def make_for_loop_generator(
446446 if isinstance (expr , IndexExpr ) and isinstance (expr .index , SliceExpr ):
447447 # TODO: maybe we must not apply this optimization to list type specifically
448448 # because the need to check length changes at each iteration?
449- start = expr .index .start
450- stop = expr .index .stop
451- step = expr .index .step
452-
453- if all (
454- s is None or isinstance (constant_fold_expr (builder , s ), int )
455- for s in (start , stop , step )
456- ):
449+
450+ def constant_fold_or_none (expr : Expression | None ) -> Any :
451+ return None if expr is None else constant_fold_expr (builder , expr )
452+
453+ start = constant_fold_or_none (expr .index .start )
454+ stop = constant_fold_or_none (expr .index .stop )
455+ step = constant_fold_or_none (expr .index .step )
456+
457+ if all (s is None or isinstance (s , int ) for s in (start , stop , step )):
457458 for_list .init (
458459 builder .accept (expr .base ),
459460 target_type ,
460461 reverse = False ,
461- start = constant_fold_expr ( builder , start ) ,
462- stop = constant_fold_expr ( builder , stop ) ,
463- step = constant_fold_expr ( builder , step ) ,
462+ start = start ,
463+ stop = stop ,
464+ step = step ,
464465 )
465466 return for_list
466467
You can’t perform that action at this time.
0 commit comments