mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 12:55:05 +00:00
Update ArgumentsParentheses
usage (#6070)
This commit is contained in:
parent
5f63b8bfb8
commit
f5c69c1b34
2 changed files with 16 additions and 6 deletions
|
@ -27,8 +27,7 @@ impl FormatNodeRule<ExprLambda> for FormatExprLambda {
|
||||||
f,
|
f,
|
||||||
[
|
[
|
||||||
space(),
|
space(),
|
||||||
args.format()
|
args.format().with_options(ArgumentsParentheses::Never),
|
||||||
.with_options(ArgumentsParentheses::SkipInsideLambda),
|
|
||||||
]
|
]
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,11 +18,22 @@ use crate::FormatNodeRule;
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Debug, Default)]
|
#[derive(Eq, PartialEq, Debug, Default)]
|
||||||
pub enum ArgumentsParentheses {
|
pub enum ArgumentsParentheses {
|
||||||
|
/// By default, arguments will always preserve their surrounding parentheses.
|
||||||
#[default]
|
#[default]
|
||||||
Default,
|
Preserve,
|
||||||
|
|
||||||
/// Arguments should never be inside parentheses for lambda expressions.
|
/// Handle special cases where parentheses should never be used.
|
||||||
SkipInsideLambda,
|
///
|
||||||
|
/// An example where parentheses are never used for arguments would be with lambda
|
||||||
|
/// expressions. The following is invalid syntax:
|
||||||
|
/// ```python
|
||||||
|
/// lambda (x, y, z): ...
|
||||||
|
/// ```
|
||||||
|
/// Instead the lambda here should be:
|
||||||
|
/// ```python
|
||||||
|
/// lambda x, y, z: ...
|
||||||
|
/// ```
|
||||||
|
Never,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -190,7 +201,7 @@ impl FormatNodeRule<Arguments> for FormatArguments {
|
||||||
+ kwonlyargs.len()
|
+ kwonlyargs.len()
|
||||||
+ usize::from(kwarg.is_some());
|
+ usize::from(kwarg.is_some());
|
||||||
|
|
||||||
if self.parentheses == ArgumentsParentheses::SkipInsideLambda {
|
if self.parentheses == ArgumentsParentheses::Never {
|
||||||
group(&format_inner).fmt(f)?;
|
group(&format_inner).fmt(f)?;
|
||||||
} else if num_arguments == 0 {
|
} else if num_arguments == 0 {
|
||||||
// No arguments, format any dangling comments between `()`
|
// No arguments, format any dangling comments between `()`
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue