mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:45:01 +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,3 +1,4 @@
|
|||
use crate::expression::maybe_parenthesize_expression;
|
||||
use crate::expression::parentheses::Parenthesize;
|
||||
use crate::prelude::*;
|
||||
use crate::FormatNodeRule;
|
||||
|
@ -18,7 +19,7 @@ impl FormatNodeRule<Decorator> for FormatDecorator {
|
|||
f,
|
||||
[
|
||||
text("@"),
|
||||
expression.format().with_options(Parenthesize::Optional)
|
||||
maybe_parenthesize_expression(expression, item, Parenthesize::Optional)
|
||||
]
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use crate::comments::trailing_comments;
|
||||
use crate::expression::maybe_parenthesize_expression;
|
||||
use crate::expression::parentheses::Parenthesize;
|
||||
use crate::prelude::*;
|
||||
use crate::{FormatNodeRule, PyFormatter};
|
||||
|
@ -60,7 +61,10 @@ impl FormatNodeRule<ExceptHandlerExceptHandler> for FormatExceptHandlerExceptHan
|
|||
if let Some(type_) = type_ {
|
||||
write!(
|
||||
f,
|
||||
[space(), type_.format().with_options(Parenthesize::IfBreaks)]
|
||||
[
|
||||
space(),
|
||||
maybe_parenthesize_expression(type_, item, Parenthesize::IfBreaks)
|
||||
]
|
||||
)?;
|
||||
if let Some(name) = name {
|
||||
write!(f, [space(), text("as"), space(), name.format()])?;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::expression::maybe_parenthesize_expression;
|
||||
use crate::expression::parentheses::Parenthesize;
|
||||
use crate::prelude::*;
|
||||
use crate::{FormatNodeRule, PyFormatter};
|
||||
|
@ -18,7 +19,11 @@ impl FormatNodeRule<WithItem> for FormatWithItem {
|
|||
let inner = format_with(|f| {
|
||||
write!(
|
||||
f,
|
||||
[context_expr.format().with_options(Parenthesize::IfBreaks)]
|
||||
[maybe_parenthesize_expression(
|
||||
context_expr,
|
||||
item,
|
||||
Parenthesize::IfBreaks
|
||||
)]
|
||||
)?;
|
||||
if let Some(optional_vars) = optional_vars {
|
||||
write!(f, [space(), text("as"), space(), optional_vars.format()])?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue