refactor: Rename FormatStringContinuation to FormatImplicitConcatenatedString (#13531)

This commit is contained in:
Micha Reiser 2024-09-27 10:24:50 +02:00 committed by GitHub
parent c046101b79
commit 253f5f269a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 40 additions and 23 deletions

View file

@ -20,7 +20,7 @@ use crate::expression::parentheses::{
};
use crate::expression::OperatorPrecedence;
use crate::prelude::*;
use crate::string::{AnyString, FormatStringContinuation};
use crate::string::{AnyString, FormatImplicitConcatenatedString};
#[derive(Copy, Clone, Debug)]
pub(super) enum BinaryLike<'a> {
@ -394,10 +394,10 @@ impl Format<PyFormatContext<'_>> for BinaryLike<'_> {
[
operand.leading_binary_comments().map(leading_comments),
leading_comments(comments.leading(string_constant)),
// Call `FormatStringContinuation` directly to avoid formatting
// Call `FormatImplicitConcatenatedString` directly to avoid formatting
// the implicitly concatenated string with the enclosing group
// because the group is added by the binary like formatting.
FormatStringContinuation::new(&string_constant),
FormatImplicitConcatenatedString::new(string_constant),
trailing_comments(comments.trailing(string_constant)),
operand.trailing_binary_comments().map(trailing_comments),
line_suffix_boundary(),
@ -413,10 +413,10 @@ impl Format<PyFormatContext<'_>> for BinaryLike<'_> {
f,
[
leading_comments(comments.leading(string_constant)),
// Call `FormatStringContinuation` directly to avoid formatting
// Call `FormatImplicitConcatenatedString` directly to avoid formatting
// the implicitly concatenated string with the enclosing group
// because the group is added by the binary like formatting.
FormatStringContinuation::new(&string_constant),
FormatImplicitConcatenatedString::new(string_constant),
trailing_comments(comments.trailing(string_constant)),
]
)?;

View file

@ -5,7 +5,7 @@ use crate::expression::parentheses::{
in_parentheses_only_group, NeedsParentheses, OptionalParentheses,
};
use crate::prelude::*;
use crate::string::{AnyString, FormatStringContinuation};
use crate::string::{AnyString, FormatImplicitConcatenatedString};
#[derive(Default)]
pub struct FormatExprBytesLiteral;
@ -16,8 +16,7 @@ impl FormatNodeRule<ExprBytesLiteral> for FormatExprBytesLiteral {
match value.as_slice() {
[bytes_literal] => bytes_literal.format().fmt(f),
_ => in_parentheses_only_group(&FormatStringContinuation::new(&AnyString::Bytes(item)))
.fmt(f),
_ => in_parentheses_only_group(&FormatImplicitConcatenatedString::new(item)).fmt(f),
}
}
}

View file

@ -7,7 +7,7 @@ use crate::expression::parentheses::{
};
use crate::other::f_string_part::FormatFStringPart;
use crate::prelude::*;
use crate::string::{AnyString, FormatStringContinuation, Quoting};
use crate::string::{AnyString, FormatImplicitConcatenatedString, Quoting};
#[derive(Default)]
pub struct FormatExprFString;
@ -22,10 +22,7 @@ impl FormatNodeRule<ExprFString> for FormatExprFString {
f_string_quoting(item, &f.context().locator()),
)
.fmt(f),
_ => {
in_parentheses_only_group(&FormatStringContinuation::new(&AnyString::FString(item)))
.fmt(f)
}
_ => in_parentheses_only_group(&FormatImplicitConcatenatedString::new(item)).fmt(f),
}
}
}

View file

@ -6,7 +6,7 @@ use crate::expression::parentheses::{
};
use crate::other::string_literal::{FormatStringLiteral, StringLiteralKind};
use crate::prelude::*;
use crate::string::{AnyString, FormatStringContinuation};
use crate::string::{AnyString, FormatImplicitConcatenatedString};
#[derive(Default)]
pub struct FormatExprStringLiteral {
@ -55,7 +55,7 @@ impl FormatNodeRule<ExprStringLiteral> for FormatExprStringLiteral {
// ensures that the docstring is a *single* string literal.
assert!(!self.kind.is_docstring());
in_parentheses_only_group(&FormatStringContinuation::new(&AnyString::String(item)))
in_parentheses_only_group(&FormatImplicitConcatenatedString::new(item))
}
.fmt(f),
}