mirror of
https://github.com/astral-sh/ruff
synced 2026-01-22 22:10:48 -05:00
Add support for reformatting byte strings (#3176)
This commit is contained in:
@@ -652,7 +652,7 @@ fn format_constant(
|
||||
write!(f, [text("False")])?;
|
||||
}
|
||||
}
|
||||
Constant::Str(_) => write!(f, [string_literal(expr)])?,
|
||||
Constant::Str(_) | Constant::Bytes(_) => write!(f, [string_literal(expr)])?,
|
||||
_ => write!(f, [literal(Range::from_located(expr))])?,
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -37,6 +37,7 @@ impl Format<ASTFormatContext<'_>> for StringLiteralPart {
|
||||
}
|
||||
}
|
||||
|
||||
// Retain raw prefixes.
|
||||
let mut is_raw = false;
|
||||
if leading_quote.contains('r') {
|
||||
is_raw = true;
|
||||
@@ -46,6 +47,11 @@ impl Format<ASTFormatContext<'_>> for StringLiteralPart {
|
||||
f.write_element(FormatElement::StaticText { text: "R" })?;
|
||||
}
|
||||
|
||||
// Normalize bytes literals to use b"...".
|
||||
if leading_quote.contains('b') || leading_quote.contains('B') {
|
||||
f.write_element(FormatElement::StaticText { text: "b" })?;
|
||||
}
|
||||
|
||||
if trailing_quote.len() == 1 {
|
||||
// Single-quoted string.
|
||||
if dquotes == 0 || squotes > 0 {
|
||||
|
||||
Reference in New Issue
Block a user