Skip to content

Commit

Permalink
πŸ› fix: check node.left in constant_folding
Browse files Browse the repository at this point in the history
  • Loading branch information
SigureMo committed Sep 2, 2024
1 parent 74d035a commit e4c5a33
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/expr_simplifier/transforms/constant_folding.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ def visit(self, node: ast.AST) -> ast.AST:
return fold_to_constant(node)
if isinstance(node, ast.BoolOp) and all(isinstance(value, ast.Constant) for value in node.values):
return fold_to_constant(node)
if isinstance(node, ast.Compare) and all(isinstance(comp, ast.Constant) for comp in node.comparators):
if isinstance(node, ast.Compare) and all(
isinstance(comp, ast.Constant) for comp in [node.left, *node.comparators]
):
return fold_to_constant(node)
if isinstance(node, ast.JoinedStr) and all(
isinstance(value, ast.Constant)
Expand Down
1 change: 1 addition & 0 deletions tests/test_transforms/test_constant_folding.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
("(1 > 2) * a", "False * a"),
("""f'Hello {"World"}!'""", "'Hello World!'"),
("(___x := 1) + 2 + ___x", "4"),
("a == 1", "a == 1"),
],
)
def test_constant_folding(expr: str, expected: str):
Expand Down

0 comments on commit e4c5a33

Please sign in to comment.