MCPcopy Create free account
hub / github.com/astral-sh/ruff / fmt_fields

Method fmt_fields

crates/ruff_python_formatter/src/other/f_string.rs:16–39  ·  view source on GitHub ↗
(&self, item: &FString, f: &mut PyFormatter)

Source from the content-addressed store, hash-verified

14
15impl FormatNodeRule<FString> for FormatFString {
16 fn fmt_fields(&self, item: &FString, f: &mut PyFormatter) -> FormatResult<()> {
17 let normalizer = StringNormalizer::from_context(f.context());
18
19 let string_kind = normalizer.choose_quotes(item.into()).flags();
20
21 let context = InterpolatedStringContext::new(
22 string_kind,
23 InterpolatedStringLayout::from_interpolated_string_elements(
24 &item.elements,
25 f.context().source(),
26 ),
27 );
28
29 // Starting prefix and quote
30 let quotes = StringQuotes::from(string_kind);
31 write!(f, [string_kind.prefix(), quotes])?;
32
33 for element in &item.elements {
34 FormatInterpolatedStringElement::new(element, context).fmt(f)?;
35 }
36
37 // Ending quote
38 quotes.fmt(f)
39 }
40}

Callers

nothing calls this directly

Calls 5

choose_quotesMethod · 0.80
contextMethod · 0.45
flagsMethod · 0.45
sourceMethod · 0.45
fmtMethod · 0.45

Tested by

no test coverage detected