mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 04:19:18 +00:00
Pass parent to NeedsParentheses
(#5708)
This commit is contained in:
parent
30702c2977
commit
067b2a6ce6
55 changed files with 562 additions and 606 deletions
|
@ -1,8 +1,9 @@
|
|||
use crate::expression::parentheses::{is_expression_parenthesized, Parenthesize};
|
||||
use crate::expression::string::StringLayout;
|
||||
use rustpython_parser::ast::StmtExpr;
|
||||
|
||||
use crate::expression::maybe_parenthesize_expression;
|
||||
use crate::expression::parentheses::Parenthesize;
|
||||
use crate::prelude::*;
|
||||
use crate::FormatNodeRule;
|
||||
use rustpython_parser::ast::StmtExpr;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtExpr;
|
||||
|
@ -11,14 +12,6 @@ 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().source())
|
||||
{
|
||||
return constant.format().with_options(StringLayout::Flat).fmt(f);
|
||||
}
|
||||
}
|
||||
|
||||
value.format().with_options(Parenthesize::Optional).fmt(f)
|
||||
maybe_parenthesize_expression(value, item, Parenthesize::Optional).fmt(f)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue