mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:37 +00:00
Refactor: Remove StringPart
and AnyStringPart
in favor of StringLikePart
(#13772)
This commit is contained in:
parent
b85be6297e
commit
8f5b2aac9a
11 changed files with 137 additions and 288 deletions
|
@ -1,12 +1,12 @@
|
|||
use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule};
|
||||
use ruff_python_ast::AnyNodeRef;
|
||||
use ruff_python_ast::{AnyNodeRef, StringLike};
|
||||
use ruff_python_ast::{CmpOp, ExprCompare};
|
||||
|
||||
use crate::expression::binary_like::BinaryLike;
|
||||
use crate::expression::has_parentheses;
|
||||
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
||||
use crate::prelude::*;
|
||||
use crate::string::AnyString;
|
||||
use crate::string::StringLikeExtensions;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatExprCompare;
|
||||
|
@ -26,7 +26,7 @@ impl NeedsParentheses for ExprCompare {
|
|||
) -> OptionalParentheses {
|
||||
if parent.is_expr_await() {
|
||||
OptionalParentheses::Always
|
||||
} else if let Some(string) = AnyString::from_expression(&self.left) {
|
||||
} else if let Ok(string) = StringLike::try_from(&*self.left) {
|
||||
// Multiline strings are guaranteed to never fit, avoid adding unnecessary parentheses
|
||||
if !string.is_implicit_concatenated()
|
||||
&& string.is_multiline(context.source())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue