Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid trailing comma for single-argument with positional separator #9076

Merged
merged 1 commit into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,13 @@ def default_arg_comments2(#
#
):
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
2 changes: 1 addition & 1 deletion crates/ruff_python_formatter/src/other/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl FormatNodeRule<Parameters> for FormatParameters {
let mut f = WithNodeLevel::new(NodeLevel::ParenthesizedExpression, f);
// No parameters, format any dangling comments between `()`
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
// trailing comma if the outer group breaks.
let mut f = WithNodeLevel::new(NodeLevel::ParenthesizedExpression, f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,16 @@ def default_arg_comments2(#
#
):
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
Expand Down Expand Up @@ -993,6 +1003,18 @@ def default_arg_comments2( #
#
):
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
```


Expand Down
Loading