mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 22:31:23 +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
|
@ -398,7 +398,7 @@ impl DunderReplacement {
|
||||||
"__or__" => Some(Self::Operator(
|
"__or__" => Some(Self::Operator(
|
||||||
"|",
|
"|",
|
||||||
"Use `|` operator",
|
"Use `|` operator",
|
||||||
OperatorPrecedence::BitXorOr,
|
OperatorPrecedence::BitOr,
|
||||||
)),
|
)),
|
||||||
"__rshift__" => Some(Self::Operator(
|
"__rshift__" => Some(Self::Operator(
|
||||||
">>",
|
">>",
|
||||||
|
@ -418,7 +418,7 @@ impl DunderReplacement {
|
||||||
"__xor__" => Some(Self::Operator(
|
"__xor__" => Some(Self::Operator(
|
||||||
"^",
|
"^",
|
||||||
"Use `^` operator",
|
"Use `^` operator",
|
||||||
OperatorPrecedence::BitXorOr,
|
OperatorPrecedence::BitXor,
|
||||||
)),
|
)),
|
||||||
|
|
||||||
"__radd__" => Some(Self::ROperator(
|
"__radd__" => Some(Self::ROperator(
|
||||||
|
@ -454,7 +454,7 @@ impl DunderReplacement {
|
||||||
"__ror__" => Some(Self::ROperator(
|
"__ror__" => Some(Self::ROperator(
|
||||||
"|",
|
"|",
|
||||||
"Use `|` operator",
|
"Use `|` operator",
|
||||||
OperatorPrecedence::BitXorOr,
|
OperatorPrecedence::BitOr,
|
||||||
)),
|
)),
|
||||||
"__rrshift__" => Some(Self::ROperator(
|
"__rrshift__" => Some(Self::ROperator(
|
||||||
">>",
|
">>",
|
||||||
|
@ -474,7 +474,7 @@ impl DunderReplacement {
|
||||||
"__rxor__" => Some(Self::ROperator(
|
"__rxor__" => Some(Self::ROperator(
|
||||||
"^",
|
"^",
|
||||||
"Use `^` operator",
|
"Use `^` operator",
|
||||||
OperatorPrecedence::BitXorOr,
|
OperatorPrecedence::BitXor,
|
||||||
)),
|
)),
|
||||||
|
|
||||||
"__aiter__" => Some(Self::Builtin("aiter", "Use `aiter()` builtin")),
|
"__aiter__" => Some(Self::Builtin("aiter", "Use `aiter()` builtin")),
|
||||||
|
|
|
@ -28,8 +28,10 @@ pub enum OperatorPrecedence {
|
||||||
/// Precedence of comparisons (`<`, `<=`, `>`, `>=`, `!=`, `==`),
|
/// Precedence of comparisons (`<`, `<=`, `>`, `>=`, `!=`, `==`),
|
||||||
/// memberships (`in`, `not in`) and identity tests (`is`, `is not`).
|
/// memberships (`in`, `not in`) and identity tests (`is`, `is not`).
|
||||||
ComparisonsMembershipIdentity,
|
ComparisonsMembershipIdentity,
|
||||||
/// Precedence of bitwise `|` and `^` operators.
|
/// Precedence of bitwise `|` operator.
|
||||||
BitXorOr,
|
BitOr,
|
||||||
|
/// Precedence of bitwise `^` operator.
|
||||||
|
BitXor,
|
||||||
/// Precedence of bitwise `&` operator.
|
/// Precedence of bitwise `&` operator.
|
||||||
BitAnd,
|
BitAnd,
|
||||||
/// Precedence of left and right shift expressions (`<<`, `>>`).
|
/// Precedence of left and right shift expressions (`<<`, `>>`).
|
||||||
|
@ -159,7 +161,8 @@ impl From<Operator> for OperatorPrecedence {
|
||||||
Operator::LShift | Operator::RShift => Self::LeftRightShift,
|
Operator::LShift | Operator::RShift => Self::LeftRightShift,
|
||||||
// Bitwise operations: &, ^, |
|
// Bitwise operations: &, ^, |
|
||||||
Operator::BitAnd => Self::BitAnd,
|
Operator::BitAnd => Self::BitAnd,
|
||||||
Operator::BitXor | Operator::BitOr => Self::BitXorOr,
|
Operator::BitXor => Self::BitXor,
|
||||||
|
Operator::BitOr => Self::BitOr,
|
||||||
// Exponentiation **
|
// Exponentiation **
|
||||||
Operator::Pow => Self::Exponent,
|
Operator::Pow => Self::Exponent,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue