mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-16 08:30:30 +00:00
Avoid trailing comma for single-argument with positional separator (#9076)
## Summary In https://github.com/astral-sh/ruff/pull/8921, we changed our parameter formatting behavior to add a trailing comma whenever a single-argument function breaks. This introduced a deviation in the case that a function contains a single argument, but _also_ includes a positional-only or keyword-only separator. Closes https://github.com/astral-sh/ruff/issues/9074.
This commit is contained in:
parent
6c2613b44e
commit
febc69ab48
3 changed files with 33 additions and 1 deletions
|
@ -410,3 +410,13 @@ def default_arg_comments2(#
|
||||||
#
|
#
|
||||||
):
|
):
|
||||||
print(x)
|
print(x)
|
||||||
|
|
||||||
|
def function_with_one_argument_and_a_positional_separator(
|
||||||
|
argument: str, /
|
||||||
|
) -> ReallyReallyReallyReallyReallyReallyReallyReallyLongName:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def function_with_one_argument_and_a_keyword_separator(
|
||||||
|
*, argument: str
|
||||||
|
) -> ReallyReallyReallyReallyReallyReallyReallyReallyLongName:
|
||||||
|
pass
|
||||||
|
|
|
@ -252,7 +252,7 @@ impl FormatNodeRule<Parameters> for FormatParameters {
|
||||||
let mut f = WithNodeLevel::new(NodeLevel::ParenthesizedExpression, f);
|
let mut f = WithNodeLevel::new(NodeLevel::ParenthesizedExpression, f);
|
||||||
// No parameters, format any dangling comments between `()`
|
// No parameters, format any dangling comments between `()`
|
||||||
write!(f, [empty_parenthesized("(", dangling, ")")])
|
write!(f, [empty_parenthesized("(", dangling, ")")])
|
||||||
} else if num_parameters == 1 {
|
} else if num_parameters == 1 && posonlyargs.is_empty() && kwonlyargs.is_empty() {
|
||||||
// If we have a single argument, avoid the inner group, to ensure that we insert a
|
// If we have a single argument, avoid the inner group, to ensure that we insert a
|
||||||
// trailing comma if the outer group breaks.
|
// trailing comma if the outer group breaks.
|
||||||
let mut f = WithNodeLevel::new(NodeLevel::ParenthesizedExpression, f);
|
let mut f = WithNodeLevel::new(NodeLevel::ParenthesizedExpression, f);
|
||||||
|
|
|
@ -416,6 +416,16 @@ def default_arg_comments2(#
|
||||||
#
|
#
|
||||||
):
|
):
|
||||||
print(x)
|
print(x)
|
||||||
|
|
||||||
|
def function_with_one_argument_and_a_positional_separator(
|
||||||
|
argument: str, /
|
||||||
|
) -> ReallyReallyReallyReallyReallyReallyReallyReallyLongName:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def function_with_one_argument_and_a_keyword_separator(
|
||||||
|
*, argument: str
|
||||||
|
) -> ReallyReallyReallyReallyReallyReallyReallyReallyLongName:
|
||||||
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
## Output
|
## Output
|
||||||
|
@ -993,6 +1003,18 @@ def default_arg_comments2( #
|
||||||
#
|
#
|
||||||
):
|
):
|
||||||
print(x)
|
print(x)
|
||||||
|
|
||||||
|
|
||||||
|
def function_with_one_argument_and_a_positional_separator(
|
||||||
|
argument: str, /
|
||||||
|
) -> ReallyReallyReallyReallyReallyReallyReallyReallyLongName:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def function_with_one_argument_and_a_keyword_separator(
|
||||||
|
*, argument: str
|
||||||
|
) -> ReallyReallyReallyReallyReallyReallyReallyReallyLongName:
|
||||||
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue