mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 12:29:28 +00:00
Separate BitXorOr
into BitXor
and BitOr
precedence (#16844)
## Summary This change follows up on the bug-fix requested in #16747 -- `ruff_python_ast::OperatorPrecedence` had an enum variant, `BitXorOr`, which which gave the same precedence to the `|` and `^` operators. This goes against [Python's documentation for operator precedence](https://docs.python.org/3/reference/expressions.html#operator-precedence), so this PR changes the code so that it's correct. This is part of the overall effort to unify redundant definitions of `OperatorPrecedence` throughout the codebase (#16071) ## Test Plan Because this is an internal change, I only ran existing tests to ensure nothing was broken.
This commit is contained in:
parent
74f64d3f96
commit
47c4ccff5d
2 changed files with 10 additions and 7 deletions
|
@ -28,8 +28,10 @@ pub enum OperatorPrecedence {
|
|||
/// Precedence of comparisons (`<`, `<=`, `>`, `>=`, `!=`, `==`),
|
||||
/// memberships (`in`, `not in`) and identity tests (`is`, `is not`).
|
||||
ComparisonsMembershipIdentity,
|
||||
/// Precedence of bitwise `|` and `^` operators.
|
||||
BitXorOr,
|
||||
/// Precedence of bitwise `|` operator.
|
||||
BitOr,
|
||||
/// Precedence of bitwise `^` operator.
|
||||
BitXor,
|
||||
/// Precedence of bitwise `&` operator.
|
||||
BitAnd,
|
||||
/// Precedence of left and right shift expressions (`<<`, `>>`).
|
||||
|
@ -159,7 +161,8 @@ impl From<Operator> for OperatorPrecedence {
|
|||
Operator::LShift | Operator::RShift => Self::LeftRightShift,
|
||||
// Bitwise operations: &, ^, |
|
||||
Operator::BitAnd => Self::BitAnd,
|
||||
Operator::BitXor | Operator::BitOr => Self::BitXorOr,
|
||||
Operator::BitXor => Self::BitXor,
|
||||
Operator::BitOr => Self::BitOr,
|
||||
// Exponentiation **
|
||||
Operator::Pow => Self::Exponent,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue