mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-16 00:20:38 +00:00
![]() ## Summary This PR fixes some misformattings around optional parentheses for expressions. I first noticed that we were misformatting this: ```python return ( unicodedata.normalize("NFKC", s1).casefold() == unicodedata.normalize("NFKC", s2).casefold() ) ``` The above is stable Black formatting, but we were doing: ```python return unicodedata.normalize("NFKC", s1).casefold() == unicodedata.normalize( "NFKC", s2 ).casefold() ``` Above, the "last" expression is a function call, so our `can_omit_optional_parentheses` was returning `true`... However, it turns out that Black treats function calls differently depending on whether or not they have arguments -- presumedly because they'll never split empty parentheses, and so they're functionally non-useful. On further investigation, I believe this applies to all parenthesized expressions. If Black can't split on the parentheses, it doesn't leverage them when removing optional parentheses. ## Test Plan Nice increase in similarity scores. Before: - `zulip`: 0.99702 - `django`: 0.99784 - `warehouse`: 0.99585 - `build`: 0.75623 - `transformers`: 0.99470 - `cpython`: 0.75989 - `typeshed`: 0.74853 After: - `zulip`: 0.99705 - `django`: 0.99795 - `warehouse`: 0.99600 - `build`: 0.75623 - `transformers`: 0.99471 - `cpython`: 0.75989 - `typeshed`: 0.74853 |
||
---|---|---|
.. | ||
mod.rs | ||
stmt_ann_assign.rs | ||
stmt_assert.rs | ||
stmt_assign.rs | ||
stmt_aug_assign.rs | ||
stmt_break.rs | ||
stmt_class_def.rs | ||
stmt_continue.rs | ||
stmt_delete.rs | ||
stmt_expr.rs | ||
stmt_for.rs | ||
stmt_function_def.rs | ||
stmt_global.rs | ||
stmt_if.rs | ||
stmt_import.rs | ||
stmt_import_from.rs | ||
stmt_ipy_escape_command.rs | ||
stmt_match.rs | ||
stmt_nonlocal.rs | ||
stmt_pass.rs | ||
stmt_raise.rs | ||
stmt_return.rs | ||
stmt_try.rs | ||
stmt_try_star.rs | ||
stmt_type_alias.rs | ||
stmt_while.rs | ||
stmt_with.rs | ||
suite.rs |