Remove FormatFStringPart (#14448)

## Summary

This is just a small refactor to remove the `FormatFStringPart` as it's
only used in the case when the f-string is not implicitly concatenated
in which case the only part is going to be `FString`. In implicitly
concatenated f-strings, we use `StringLike` instead.
This commit is contained in:
Dhruv Manilawala 2024-11-25 10:29:22 +05:30 committed by GitHub
parent ac23c99744
commit efe54081d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 42 deletions

View file

@ -4,7 +4,7 @@ use ruff_text_size::TextSlice;
use crate::expression::parentheses::{
in_parentheses_only_group, NeedsParentheses, OptionalParentheses,
};
use crate::other::f_string_part::FormatFStringPart;
use crate::other::f_string::FormatFString;
use crate::prelude::*;
use crate::string::implicit::FormatImplicitConcatenatedStringFlat;
use crate::string::{implicit::FormatImplicitConcatenatedString, Quoting, StringLikeExtensions};
@ -17,8 +17,11 @@ impl FormatNodeRule<ExprFString> for FormatExprFString {
let ExprFString { value, .. } = item;
if let [f_string_part] = value.as_slice() {
FormatFStringPart::new(f_string_part, f_string_quoting(item, f.context().source()))
.fmt(f)
// SAFETY: A single string literal cannot be an f-string. This is guaranteed by the
// [`ruff_python_ast::FStringValue::single`] constructor.
let f_string = f_string_part.as_f_string().unwrap();
FormatFString::new(f_string, f_string_quoting(item, f.context().source())).fmt(f)
} else {
// Always join fstrings that aren't parenthesized and thus, are always on a single line.
if !f.context().node_level().is_parenthesized() {