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

Method fmt

crates/ruff_python_formatter/src/string/implicit.rs:44–66  ·  view source on GitHub ↗
(&self, f: &mut PyFormatter)

Source from the content-addressed store, hash-verified

42
43impl Format<PyFormatContext<'_>> for FormatImplicitConcatenatedString<'_> {
44 fn fmt(&self, f: &mut PyFormatter) -> FormatResult<()> {
45 let flat = FormatImplicitConcatenatedStringFlat::new(self.string, f.context());
46 let expanded = FormatImplicitConcatenatedStringExpanded::new(
47 self.string,
48 if flat.is_some() {
49 ImplicitConcatenatedLayout::MaybeFlat
50 } else {
51 ImplicitConcatenatedLayout::Multipart
52 },
53 );
54
55 // If the string can be joined, try joining the implicit concatenated string into a single string
56 // if it fits on the line. Otherwise, parenthesize the string parts and format each part on its
57 // own line.
58 if let Some(flat) = flat {
59 write!(
60 f,
61 [if_group_fits_on_line(&flat), if_group_breaks(&expanded)]
62 )
63 } else {
64 expanded.fmt(f)
65 }
66 }
67}
68
69/// Formats an implicit concatenated string where parts are separated by a space or line break.

Callers

nothing calls this directly

Calls 15

expand_parentFunction · 0.85
format_withFunction · 0.85
normalize_stringFunction · 0.85
source_text_sliceFunction · 0.85
textFunction · 0.85
needs_chaperone_spaceFunction · 0.85
OkClass · 0.85
join_withMethod · 0.80
trim_startMethod · 0.80
enter_stringMethod · 0.80

Tested by

no test coverage detected