Skip to content

Commit

Permalink
Context is already aware of f-string state
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Feb 14, 2024
1 parent f1c2fc8 commit 4c62227
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 17 deletions.
12 changes: 0 additions & 12 deletions crates/ruff_python_formatter/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,6 @@ impl<'a> PyFormatContext<'a> {
self.f_string_state = f_string_state;
}

/// Return a new context suitable for formatting an expression inside an
/// f-string.
///
/// The `quotes` parameter should be the quote information of the f-string
/// containing the expression.
pub(crate) fn in_f_string(self, quotes: StringQuotes) -> PyFormatContext<'a> {
PyFormatContext {
f_string_state: FStringState::Inside(quotes),
..self
}
}

/// Returns a new context with the given set of options.
pub(crate) fn with_options(mut self, options: PyFormatOptions) -> Self {
self.options = options;
Expand Down
6 changes: 1 addition & 5 deletions crates/ruff_python_formatter/src/other/f_string_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,7 @@ impl Format<PyFormatContext<'_>> for FormatFStringExpressionElement<'_> {
.clone()
.with_line_width(NonZeroU16::MAX.into())
.with_magic_trailing_comma(MagicTrailingComma::Ignore);
let context = f
.context()
.clone()
.in_f_string(self.context.quotes())
.with_options(options);
let context = f.context().clone().with_options(options);
let formatted = crate::format!(context, [expression.format()])?;
text(formatted.print()?.as_code()).fmt(f)?;
} else {
Expand Down

0 comments on commit 4c62227

Please sign in to comment.