Skip to content

Conversation

@junhsonjb
Copy link
Contributor

Summary

This change begins to resolve #16071 by moving the OperatorPrecedence structs from the ruff_python_linter crate into ruff_python_ast. This PR also implements precedence() methods on the Expr and ExprRef enums.

Test Plan

Since this change mainly shifts existing logic, I didn't add any additional tests. Existing tests do pass.

@junhsonjb junhsonjb mentioned this pull request Feb 14, 2025
2 tasks
@github-actions
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@MichaReiser MichaReiser added the internal An internal refactor or improvement label Feb 14, 2025
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet

@MichaReiser MichaReiser merged commit fa28dc5 into astral-sh:main Feb 14, 2025
21 checks passed
Operator::LShift | Operator::RShift => Self::LeftRightShift,
// Bitwise operations: &, ^, |
Operator::BitAnd => Self::BitAnd,
Operator::BitXor | Operator::BitOr => Self::BitXorOr,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think both BitXor and BitOr are at the same precedence level (https://docs.python.org/3/reference/expressions.html#operator-precedence).

dhruvmanila pushed a commit that referenced this pull request Mar 21, 2025
## Summary

This change continues to resolve #16071 (and continues the work started
in #16162). Specifically, this PR changes the code in the parser so that
it uses the `OperatorPrecedence` struct from `ruff_python_ast` instead
of its own version. This is part of an effort to get rid of the
redundant definitions of `OperatorPrecedence` throughout the codebase.

Note that this PR only makes this change for `ruff_python_parser` -- we
still want to make a similar change for the formatter (namely the
`OperatorPrecedence` defined in the expression part of the formatter,
the pattern one is different). I separated the work to keep the PRs
small and easily reviewable.

## Test Plan

Because this is an internal change, I didn't add any additional tests.
Existing tests do pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal An internal refactor or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify OperatorPrecedence enums

3 participants