mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 14:21:53 +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::Parenthesize;
|
||||
use crate::{AsFormat, FormatNodeRule, PyFormatter};
|
||||
use crate::{FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::prelude::{space, text};
|
||||
use ruff_formatter::{write, Buffer, Format, FormatResult};
|
||||
|
||||
use crate::expression::maybe_parenthesize_expression;
|
||||
use rustpython_parser::ast::StmtRaise;
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -21,7 +22,10 @@ impl FormatNodeRule<StmtRaise> for FormatStmtRaise {
|
|||
if let Some(value) = exc {
|
||||
write!(
|
||||
f,
|
||||
[space(), value.format().with_options(Parenthesize::Optional)]
|
||||
[
|
||||
space(),
|
||||
maybe_parenthesize_expression(value, item, Parenthesize::Optional)
|
||||
]
|
||||
)?;
|
||||
}
|
||||
|
||||
|
@ -32,7 +36,7 @@ impl FormatNodeRule<StmtRaise> for FormatStmtRaise {
|
|||
space(),
|
||||
text("from"),
|
||||
space(),
|
||||
value.format().with_options(Parenthesize::Optional)
|
||||
maybe_parenthesize_expression(value, item, Parenthesize::Optional)
|
||||
]
|
||||
)?;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue