mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 12:55:05 +00:00
Fix invalid syntax for binary expression in unary op (#5370)
This commit is contained in:
parent
38189ed913
commit
955e9ef821
20 changed files with 200 additions and 116 deletions
|
@ -34,10 +34,10 @@ impl FormatNodeRule<ExprCompare> for FormatExprCompare {
|
|||
impl<'ast> FormatBinaryLike<'ast> for ExprCompare {
|
||||
type FormatOperator = FormatOwnedWithRule<CmpOp, FormatCmpOp, PyFormatContext<'ast>>;
|
||||
|
||||
fn binary_layout(&self) -> BinaryLayout {
|
||||
fn binary_layout(&self, source: &str) -> BinaryLayout {
|
||||
if self.ops.len() == 1 {
|
||||
match self.comparators.as_slice() {
|
||||
[right] => BinaryLayout::from_left_right(&self.left, right),
|
||||
[right] => BinaryLayout::from_left_right(&self.left, right, source),
|
||||
[..] => BinaryLayout::Default,
|
||||
}
|
||||
} else {
|
||||
|
@ -102,7 +102,7 @@ impl NeedsParentheses for ExprCompare {
|
|||
comments: &Comments,
|
||||
) -> Parentheses {
|
||||
match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) {
|
||||
parentheses @ Parentheses::Optional => match self.binary_layout() {
|
||||
parentheses @ Parentheses::Optional => match self.binary_layout(source) {
|
||||
BinaryLayout::Default => parentheses,
|
||||
|
||||
BinaryLayout::ExpandRight
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue