Skip to content

Commit 8d44ae0

Browse files
[mypyc] feat: add ConditionalExpr support to constant_fold_expr
This PR adds ConditionalExpr support to `constant_fold_expr`
1 parent c71fef0 commit 8d44ae0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

mypy/constant_fold.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ def constant_fold_expr(expr: Expression, cur_mod_id: str) -> ConstantValue | Non
7373
value = constant_fold_expr(expr.expr, cur_mod_id)
7474
if value is not None:
7575
return constant_fold_unary_op(expr.op, value)
76+
elif isinstance(expr, ConditionalExpr):
77+
cond = constant_fold_expr(expr.cond, cur_mod_id)
78+
if cond is not None:
79+
value_expr = expr.if_expr if cond else expr.else_expr
80+
return constant_fold_expr(value_expr, cur_mod_id)
7681
return None
7782

7883

0 commit comments

Comments
 (0)