mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-28 06:14:54 +00:00
Omit tuple parentheses inside comprehensions (#5790)
This commit is contained in:
parent
38678142ed
commit
9fb8d6e999
7 changed files with 198 additions and 42 deletions
|
@ -14,6 +14,9 @@ use crate::prelude::*;
|
|||
|
||||
#[derive(Eq, PartialEq, Debug, Default)]
|
||||
pub enum TupleParentheses {
|
||||
/// Black omits parentheses for tuples inside of comprehensions.
|
||||
Comprehension,
|
||||
|
||||
/// Effectively `None` in `Option<Parentheses>`
|
||||
#[default]
|
||||
Default,
|
||||
|
@ -116,6 +119,13 @@ impl FormatNodeRule<ExprTuple> for FormatExprTuple {
|
|||
parenthesized("(", &ExprSequence::new(item), ")").fmt(f)
|
||||
}
|
||||
_ => match self.parentheses {
|
||||
TupleParentheses::Comprehension => {
|
||||
let separator =
|
||||
format_with(|f| group(&format_args![text(","), space()]).fmt(f));
|
||||
f.join_with(separator)
|
||||
.entries(elts.iter().formatted())
|
||||
.finish()
|
||||
}
|
||||
TupleParentheses::Subscript => group(&ExprSequence::new(item)).fmt(f),
|
||||
_ => parenthesize_if_expands(&ExprSequence::new(item)).fmt(f),
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue