[internal] Move Linter OperatorPrecedence into ruff_python_ast crate#16162
Merged
MichaReiser merged 4 commits intoastral-sh:mainfrom Feb 14, 2025
Merged
Conversation
2 tasks
Contributor
|
dhruvmanila
reviewed
Mar 18, 2025
| Operator::LShift | Operator::RShift => Self::LeftRightShift, | ||
| // Bitwise operations: &, ^, | | ||
| Operator::BitAnd => Self::BitAnd, | ||
| Operator::BitXor | Operator::BitOr => Self::BitXorOr, |
Member
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This change begins to resolve #16071 by moving the
OperatorPrecedencestructs from theruff_python_lintercrate intoruff_python_ast. This PR also implementsprecedence()methods on theExprandExprRefenums.Test Plan
Since this change mainly shifts existing logic, I didn't add any additional tests. Existing tests do pass.