Refactor: Remove StringPart and AnyStringPart in favor of StringLikePart (#13772)

This commit is contained in:
Micha Reiser 2024-10-16 12:52:06 +02:00 committed by GitHub
parent b85be6297e
commit 8f5b2aac9a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 137 additions and 288 deletions

View file

@ -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())