Skip to content

Commit

Permalink
tweak operator precedence
Browse files Browse the repository at this point in the history
  • Loading branch information
j-ittner committed Dec 4, 2020
1 parent 877af1b commit 7b18a22
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/pytools/expression/operator/_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ def is_unary(self) -> bool:
UnaryOperator.LAMBDA = UnaryOperator("lambda")

__OPERATOR_PRECEDENCE_ORDER: Tuple[Set[Operator], ...] = (
{BinaryOperator.COMMA},
{BinaryOperator.ASSIGN, BinaryOperator.COLON, BinaryOperator.SLICE},
{UnaryOperator.LAMBDA},
{BinaryOperator.ASSIGN},
{BinaryOperator.COMMA, UnaryOperator.LAMBDA},
{BinaryOperator.COLON, BinaryOperator.SLICE},
{BinaryOperator.OR},
{BinaryOperator.AND},
{UnaryOperator.NOT},
Expand Down
10 changes: 8 additions & 2 deletions test/test/pytools/test_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,14 @@ def test_expression_formatting() -> None:
)"""
)

expr_4 = Lambda(Id.x, body=e)(Lit(5))
assert repr(expr_4) == "(lambda x: f((1 | 2) >> 'x' % x, abc=-5))(5)"
expr_4 = Lambda(body=e)
assert repr(expr_4) == "lambda : f((1 | 2) >> 'x' % x, abc=-5)"

expr_5 = Lambda(Id.x, body=e)(Lit(5))
assert repr(expr_5) == "(lambda x: f((1 | 2) >> 'x' % x, abc=-5))(5)"

expr_6 = Lambda(Id.x, Id.y, body=e)(Lit(5), 6)
assert repr(expr_6) == "(lambda x, y: f((1 | 2) >> 'x' % x, abc=-5))(5, 6)"


def test_expression() -> None:
Expand Down

0 comments on commit 7b18a22

Please sign in to comment.