mirror of
https://github.com/astral-sh/ruff
synced 2026-01-23 06:20:55 -05:00
Format implicit string continuation (#5328)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use crate::expression::parentheses::Parenthesize;
|
||||
use crate::expression::parentheses::{is_expression_parenthesized, Parenthesize};
|
||||
use crate::expression::string::StringLayout;
|
||||
use crate::prelude::*;
|
||||
use crate::FormatNodeRule;
|
||||
use rustpython_parser::ast::StmtExpr;
|
||||
@@ -10,6 +11,14 @@ impl FormatNodeRule<StmtExpr> for FormatStmtExpr {
|
||||
fn fmt_fields(&self, item: &StmtExpr, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
let StmtExpr { value, .. } = item;
|
||||
|
||||
if let Some(constant) = value.as_constant_expr() {
|
||||
if constant.value.is_str()
|
||||
&& !is_expression_parenthesized(value.as_ref().into(), f.context().contents())
|
||||
{
|
||||
return constant.format().with_options(StringLayout::Flat).fmt(f);
|
||||
}
|
||||
}
|
||||
|
||||
value.format().with_options(Parenthesize::Optional).fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user