mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-23 20:05:15 +00:00
Move is_tuple_parenthesized
from the formatter to ruff_python_ast
(#9533)
This allows it to be used in the linter as well as the formatter. It will be useful in #9474
This commit is contained in:
parent
64aac5d526
commit
a1e65a92bd
4 changed files with 38 additions and 40 deletions
|
@ -15,7 +15,6 @@ use crate::builders::parenthesize_if_expands;
|
|||
use crate::comments::{leading_comments, trailing_comments, LeadingDanglingTrailingComments};
|
||||
use crate::context::{NodeLevel, WithNodeLevel};
|
||||
use crate::expression::expr_generator_exp::is_generator_parenthesized;
|
||||
use crate::expression::expr_tuple::is_tuple_parenthesized;
|
||||
use crate::expression::parentheses::{
|
||||
is_expression_parenthesized, optional_parentheses, parenthesized, HuggingStyle,
|
||||
NeedsParentheses, OptionalParentheses, Parentheses, Parenthesize,
|
||||
|
@ -670,7 +669,7 @@ impl<'input> CanOmitOptionalParenthesesVisitor<'input> {
|
|||
return;
|
||||
}
|
||||
|
||||
Expr::Tuple(tuple) if is_tuple_parenthesized(tuple, self.context.source()) => {
|
||||
Expr::Tuple(tuple) if tuple.is_parenthesized(self.context.source()) => {
|
||||
self.any_parenthesized_expressions = true;
|
||||
// The values are always parenthesized, don't visit.
|
||||
return;
|
||||
|
@ -1059,7 +1058,7 @@ pub(crate) fn has_own_parentheses(
|
|||
}
|
||||
}
|
||||
|
||||
Expr::Tuple(tuple) if is_tuple_parenthesized(tuple, context.source()) => {
|
||||
Expr::Tuple(tuple) if tuple.is_parenthesized(context.source()) => {
|
||||
if !tuple.elts.is_empty() || context.comments().has_dangling(AnyNodeRef::from(expr)) {
|
||||
Some(OwnParentheses::NonEmpty)
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue