Group function definition parameters with return type annotations (#6410)
## Summary This PR removes the group around function definition parameters, instead grouping the parameters with the type parameters and return type annotation. This increases Zulip's similarity score from 0.99385 to 0.99699, so it's a meaningful improvement. However, there's at least one stability error that I'm working on, and I'm really just looking for high-level feedback at this point, because I'm not happy with the solution. Closes https://github.com/astral-sh/ruff/issues/6352. ## Test Plan Before: - `zulip`: 0.99396 - `django`: 0.99784 - `warehouse`: 0.99578 - `build`: 0.75436 - `transformers`: 0.99407 - `cpython`: 0.75987 - `typeshed`: 0.74432 After: - `zulip`: 0.99702 - `django`: 0.99784 - `warehouse`: 0.99585 - `build`: 0.75623 - `transformers`: 0.99470 - `cpython`: 0.75988 - `typeshed`: 0.74853
This commit is contained in:
@@ -58,24 +58,28 @@ impl FormatNodeRule<StmtFunctionDef> for FormatStmtFunctionDef {
|
||||
write!(f, [type_params.format()])?;
|
||||
}
|
||||
|
||||
write!(f, [item.parameters.format()])?;
|
||||
|
||||
if let Some(return_annotation) = item.returns.as_ref() {
|
||||
write!(f, [space(), text("->"), space()])?;
|
||||
if return_annotation.is_tuple_expr() {
|
||||
write!(
|
||||
f,
|
||||
[return_annotation.format().with_options(Parentheses::Never)]
|
||||
)?;
|
||||
} else {
|
||||
write!(
|
||||
f,
|
||||
[optional_parentheses(
|
||||
&return_annotation.format().with_options(Parentheses::Never),
|
||||
)]
|
||||
)?;
|
||||
let format_inner = format_with(|f: &mut PyFormatter| {
|
||||
write!(f, [item.parameters.format()])?;
|
||||
if let Some(return_annotation) = item.returns.as_ref() {
|
||||
write!(f, [space(), text("->"), space()])?;
|
||||
if return_annotation.is_tuple_expr() {
|
||||
write!(
|
||||
f,
|
||||
[return_annotation.format().with_options(Parentheses::Never)]
|
||||
)?;
|
||||
} else {
|
||||
write!(
|
||||
f,
|
||||
[optional_parentheses(
|
||||
&return_annotation.format().with_options(Parentheses::Never),
|
||||
)]
|
||||
)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
});
|
||||
|
||||
write!(f, [group(&format_inner)])?;
|
||||
|
||||
write!(
|
||||
f,
|
||||
|
||||
Reference in New Issue
Block a user