Skip to content

Commit e4c5a33

Browse files
committed
πŸ› fix: check node.left in constant_folding
1 parent 74d035a commit e4c5a33

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

β€Žsrc/expr_simplifier/transforms/constant_folding.pyβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ def visit(self, node: ast.AST) -> ast.AST:
2222
return fold_to_constant(node)
2323
if isinstance(node, ast.BoolOp) and all(isinstance(value, ast.Constant) for value in node.values):
2424
return fold_to_constant(node)
25-
if isinstance(node, ast.Compare) and all(isinstance(comp, ast.Constant) for comp in node.comparators):
25+
if isinstance(node, ast.Compare) and all(
26+
isinstance(comp, ast.Constant) for comp in [node.left, *node.comparators]
27+
):
2628
return fold_to_constant(node)
2729
if isinstance(node, ast.JoinedStr) and all(
2830
isinstance(value, ast.Constant)

β€Žtests/test_transforms/test_constant_folding.pyβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
("(1 > 2) * a", "False * a"),
2020
("""f'Hello {"World"}!'""", "'Hello World!'"),
2121
("(___x := 1) + 2 + ___x", "4"),
22+
("a == 1", "a == 1"),
2223
],
2324
)
2425
def test_constant_folding(expr: str, expected: str):

0 commit comments

Comments
Β (0)