diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/function.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/function.py index 98eb09eefafcb..20eca870395fd 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/function.py +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/function.py @@ -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 diff --git a/crates/ruff_python_formatter/src/other/parameters.rs b/crates/ruff_python_formatter/src/other/parameters.rs index d095d33ae1975..c3e251ebe97e5 100644 --- a/crates/ruff_python_formatter/src/other/parameters.rs +++ b/crates/ruff_python_formatter/src/other/parameters.rs @@ -252,7 +252,7 @@ impl FormatNodeRule 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); diff --git a/crates/ruff_python_formatter/tests/snapshots/format@statement__function.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@statement__function.py.snap index 7a8e97566ecb3..4c040409d7c33 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@statement__function.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@statement__function.py.snap @@ -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 @@ -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 ```