Skip to content

Commit

Permalink
Rename FStringState::Inside -> FStringState::InsideExpressionElement
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Feb 16, 2024
1 parent f7a27c6 commit 5bafe6a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions crates/ruff_python_formatter/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ impl Debug for PyFormatContext<'_> {

#[derive(Copy, Clone, Debug, Default)]
pub(crate) enum FStringState {
/// The formatter is inside an f-string, in the replacement field i.e., `f"foo {x}"`.
/// The formatter is inside an f-string expression element i.e., between the
/// curly brace in `f"foo {x}"`.
///
/// The containing `StringQuotes` is the surrounding f-string quote information.
Inside(StringQuotes),
InsideExpressionElement(StringQuotes),
/// The formatter is outside an f-string.
#[default]
Outside,
Expand Down
5 changes: 4 additions & 1 deletion crates/ruff_python_formatter/src/other/f_string_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ impl Format<PyFormatContext<'_>> for FormatFStringExpressionElement<'_> {
bracket_spacing.fmt(f)?;

// Update the context to be inside the f-string.
let f = &mut WithFStringState::new(FStringState::Inside(self.context.quotes()), f);
let f = &mut WithFStringState::new(
FStringState::InsideExpressionElement(self.context.quotes()),
f,
);

// If we're going to remove the soft line breaks, then there's a chance
// that there will be trailing commas in the formatted expression. For
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_python_formatter/src/string/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl StringNormalizer {
self.preferred_quote_style
};

let quoting = if let FStringState::Inside(quotes) = self.f_string_state {
let quoting = if let FStringState::InsideExpressionElement(quotes) = self.f_string_state {
// If we're inside an f-string, we need to make sure to preserve the
// existing quotes unless we're inside a triple-quoted f-string and
// the inner string itself isn't triple-quoted. For example:
Expand Down

0 comments on commit 5bafe6a

Please sign in to comment.