mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-09 18:02:19 +00:00
Treat parenthesized power operands as non-simple (#7371)
Closes https://github.com/astral-sh/ruff/issues/7318.
This commit is contained in:
parent
2ddea7c657
commit
34c1cb7d11
3 changed files with 21 additions and 2 deletions
|
@ -206,6 +206,11 @@ if (
|
||||||
for user_id in set(target_user_ids) - {u.user_id for u in updates}:
|
for user_id in set(target_user_ids) - {u.user_id for u in updates}:
|
||||||
updates.append(UserPresenceState.default(user_id))
|
updates.append(UserPresenceState.default(user_id))
|
||||||
|
|
||||||
|
# If either operator is parenthesized, use non-simple formatting.
|
||||||
|
# See: https://github.com/astral-sh/ruff/issues/7318.
|
||||||
|
10**(2)
|
||||||
|
10**2
|
||||||
|
|
||||||
# Keeps parenthesized left hand sides
|
# Keeps parenthesized left hand sides
|
||||||
(
|
(
|
||||||
log(self.price / self.strike)
|
log(self.price / self.strike)
|
||||||
|
|
|
@ -466,8 +466,11 @@ impl Format<PyFormatContext<'_>> for BinaryLike<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const fn is_simple_power_expression(left: &Expr, right: &Expr) -> bool {
|
fn is_simple_power_expression(left: &Expr, right: &Expr, source: &str) -> bool {
|
||||||
is_simple_power_operand(left) && is_simple_power_operand(right)
|
is_simple_power_operand(left)
|
||||||
|
&& is_simple_power_operand(right)
|
||||||
|
&& !is_expression_parenthesized(left.into(), source)
|
||||||
|
&& !is_expression_parenthesized(right.into(), source)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return `true` if an [`Expr`] adheres to [Black's definition](https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-breaks-binary-operators)
|
/// Return `true` if an [`Expr`] adheres to [Black's definition](https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-breaks-binary-operators)
|
||||||
|
@ -661,6 +664,7 @@ impl Format<PyFormatContext<'_>> for FlatBinaryExpressionSlice<'_> {
|
||||||
&& is_simple_power_expression(
|
&& is_simple_power_expression(
|
||||||
left.last_operand().expression(),
|
left.last_operand().expression(),
|
||||||
right.first_operand().expression(),
|
right.first_operand().expression(),
|
||||||
|
f.context().source(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(leading) = left.first_operand().leading_binary_comments() {
|
if let Some(leading) = left.first_operand().leading_binary_comments() {
|
||||||
|
|
|
@ -212,6 +212,11 @@ if (
|
||||||
for user_id in set(target_user_ids) - {u.user_id for u in updates}:
|
for user_id in set(target_user_ids) - {u.user_id for u in updates}:
|
||||||
updates.append(UserPresenceState.default(user_id))
|
updates.append(UserPresenceState.default(user_id))
|
||||||
|
|
||||||
|
# If either operator is parenthesized, use non-simple formatting.
|
||||||
|
# See: https://github.com/astral-sh/ruff/issues/7318.
|
||||||
|
10**(2)
|
||||||
|
10**2
|
||||||
|
|
||||||
# Keeps parenthesized left hand sides
|
# Keeps parenthesized left hand sides
|
||||||
(
|
(
|
||||||
log(self.price / self.strike)
|
log(self.price / self.strike)
|
||||||
|
@ -657,6 +662,11 @@ if (
|
||||||
for user_id in set(target_user_ids) - {u.user_id for u in updates}:
|
for user_id in set(target_user_ids) - {u.user_id for u in updates}:
|
||||||
updates.append(UserPresenceState.default(user_id))
|
updates.append(UserPresenceState.default(user_id))
|
||||||
|
|
||||||
|
# If either operator is parenthesized, use non-simple formatting.
|
||||||
|
# See: https://github.com/astral-sh/ruff/issues/7318.
|
||||||
|
10 ** (2)
|
||||||
|
10**2
|
||||||
|
|
||||||
# Keeps parenthesized left hand sides
|
# Keeps parenthesized left hand sides
|
||||||
(
|
(
|
||||||
log(self.price / self.strike)
|
log(self.price / self.strike)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue