ruff/crates/ruff_python_formatter/src/statement
Charlie Marsh d616c9b870
Avoid omitting optional parentheses for argument-less parentheses (#6484)
## 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
2023-08-11 17:58:42 +00:00
..
mod.rs Rename Magic* to IpyEscape* (#6395) 2023-08-09 13:28:18 +00:00
stmt_ann_assign.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
stmt_assert.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
stmt_assign.rs Avoid omitting optional parentheses for argument-less parentheses (#6484) 2023-08-11 17:58:42 +00:00
stmt_aug_assign.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
stmt_break.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
stmt_class_def.rs Refactor and rename skip_trailing_trivia (#6312) 2023-08-04 13:30:53 +00:00
stmt_continue.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
stmt_delete.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
stmt_expr.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
stmt_for.rs Remove async AST node variants for with, for, and def (#6369) 2023-08-07 16:36:02 +00:00
stmt_function_def.rs Group function definition parameters with return type annotations (#6410) 2023-08-09 12:13:58 +00:00
stmt_global.rs Break global and nonlocal statements over continuation lines (#6172) 2023-08-02 19:55:00 +00:00
stmt_if.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
stmt_import.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
stmt_import_from.rs Preserve end-of-line comments on import-from statements (#6216) 2023-08-01 18:58:05 +00:00
stmt_ipy_escape_command.rs Rename Magic* to IpyEscape* (#6395) 2023-08-09 13:28:18 +00:00
stmt_match.rs Add formatting for MatchCase (#6360) 2023-08-11 19:20:25 +05:30
stmt_nonlocal.rs Break global and nonlocal statements over continuation lines (#6172) 2023-08-02 19:55:00 +00:00
stmt_pass.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
stmt_raise.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
stmt_return.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
stmt_try.rs Replace Formatter<PyFormatContext<'_>> with PyFormatter (#6330) 2023-08-04 10:48:58 +02:00
stmt_try_star.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
stmt_type_alias.rs Add formatting of type alias statements (#6162) 2023-08-02 20:40:32 +00:00
stmt_while.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
stmt_with.rs Remove async AST node variants for with, for, and def (#6369) 2023-08-07 16:36:02 +00:00
suite.rs Remove async AST node variants for with, for, and def (#6369) 2023-08-07 16:36:02 +00:00