mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-16 08:30:16 +00:00
Remove FormatFStringPart
(#14448)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Blocked by required conditions
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Blocked by required conditions
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
## 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:
parent
ac23c99744
commit
efe54081d6
3 changed files with 6 additions and 42 deletions
|
@ -4,7 +4,7 @@ use ruff_text_size::TextSlice;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
in_parentheses_only_group, NeedsParentheses, OptionalParentheses,
|
in_parentheses_only_group, NeedsParentheses, OptionalParentheses,
|
||||||
};
|
};
|
||||||
use crate::other::f_string_part::FormatFStringPart;
|
use crate::other::f_string::FormatFString;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::string::implicit::FormatImplicitConcatenatedStringFlat;
|
use crate::string::implicit::FormatImplicitConcatenatedStringFlat;
|
||||||
use crate::string::{implicit::FormatImplicitConcatenatedString, Quoting, StringLikeExtensions};
|
use crate::string::{implicit::FormatImplicitConcatenatedString, Quoting, StringLikeExtensions};
|
||||||
|
@ -17,8 +17,11 @@ impl FormatNodeRule<ExprFString> for FormatExprFString {
|
||||||
let ExprFString { value, .. } = item;
|
let ExprFString { value, .. } = item;
|
||||||
|
|
||||||
if let [f_string_part] = value.as_slice() {
|
if let [f_string_part] = value.as_slice() {
|
||||||
FormatFStringPart::new(f_string_part, f_string_quoting(item, f.context().source()))
|
// SAFETY: A single string literal cannot be an f-string. This is guaranteed by the
|
||||||
.fmt(f)
|
// [`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 {
|
} else {
|
||||||
// Always join fstrings that aren't parenthesized and thus, are always on a single line.
|
// Always join fstrings that aren't parenthesized and thus, are always on a single line.
|
||||||
if !f.context().node_level().is_parenthesized() {
|
if !f.context().node_level().is_parenthesized() {
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
use ruff_python_ast::FStringPart;
|
|
||||||
|
|
||||||
use crate::other::f_string::FormatFString;
|
|
||||||
use crate::other::string_literal::StringLiteralKind;
|
|
||||||
use crate::prelude::*;
|
|
||||||
use crate::string::Quoting;
|
|
||||||
|
|
||||||
/// Formats an f-string part which is either a string literal or an f-string.
|
|
||||||
///
|
|
||||||
/// This delegates the actual formatting to the appropriate formatter.
|
|
||||||
pub(crate) struct FormatFStringPart<'a> {
|
|
||||||
part: &'a FStringPart,
|
|
||||||
/// The quoting to be used for all the f-string parts. This is determined by
|
|
||||||
/// the parent node (f-string expression) and is required to format all parts
|
|
||||||
/// correctly.
|
|
||||||
quoting: Quoting,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> FormatFStringPart<'a> {
|
|
||||||
pub(crate) fn new(part: &'a FStringPart, quoting: Quoting) -> Self {
|
|
||||||
Self { part, quoting }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Format<PyFormatContext<'_>> for FormatFStringPart<'_> {
|
|
||||||
fn fmt(&self, f: &mut PyFormatter) -> FormatResult<()> {
|
|
||||||
match self.part {
|
|
||||||
#[allow(deprecated)]
|
|
||||||
FStringPart::Literal(string_literal) => string_literal
|
|
||||||
.format()
|
|
||||||
.with_options(StringLiteralKind::InImplicitlyConcatenatedFString(
|
|
||||||
self.quoting,
|
|
||||||
))
|
|
||||||
.fmt(f),
|
|
||||||
FStringPart::FString(f_string) => FormatFString::new(f_string, self.quoting).fmt(f),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -8,7 +8,6 @@ pub(crate) mod elif_else_clause;
|
||||||
pub(crate) mod except_handler_except_handler;
|
pub(crate) mod except_handler_except_handler;
|
||||||
pub(crate) mod f_string;
|
pub(crate) mod f_string;
|
||||||
pub(crate) mod f_string_element;
|
pub(crate) mod f_string_element;
|
||||||
pub(crate) mod f_string_part;
|
|
||||||
pub(crate) mod identifier;
|
pub(crate) mod identifier;
|
||||||
pub(crate) mod keyword;
|
pub(crate) mod keyword;
|
||||||
pub(crate) mod match_case;
|
pub(crate) mod match_case;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue