ruff/crates/ruff_python_formatter/tests/snapshots
Charlie Marsh 53246b725e
Allow return type annotations to use their own parentheses (#6436)
## Summary

This PR modifies our logic for wrapping return type annotations.
Previously, we _always_ wrapped the annotation in parentheses if it
expanded; however, Black only exhibits this behavior when the function
parameters is empty (i.e., it doesn't and can't break). In other cases,
it uses the normal parenthesization rules, allowing nodes to bring their
own parentheses.

For example, given:

```python
def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> Set[
    "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
]:
    ...

def xxxxxxxxxxxxxxxxxxxxxxxxxxxx(x) -> Set[
    "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
]:
    ...
```

Black will format as:

```python
def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> (
    Set[
        "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    ]
):
    ...


def xxxxxxxxxxxxxxxxxxxxxxxxxxxx(
    x,
) -> Set[
    "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
]:
    ...
```

Whereas, prior to this PR, Ruff would format as:

```python
def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> (
    Set[
        "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    ]
):
    ...


def xxxxxxxxxxxxxxxxxxxxxxxxxxxx(
    x,
) -> (
    Set[
        "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    ]
):
    ...
```

Closes https://github.com/astral-sh/ruff/issues/6431.

## Test Plan

Before:

- `zulip`: 0.99702
- `django`: 0.99784
- `warehouse`: 0.99585
- `build`: 0.75623
- `transformers`: 0.99470
- `cpython`: 0.75988
- `typeshed`: 0.74853

After:

- `zulip`: 0.99724
- `django`: 0.99791
- `warehouse`: 0.99586
- `build`: 0.75623
- `transformers`: 0.99474
- `cpython`: 0.75956
- `typeshed`: 0.74857
2023-08-11 18:19:21 +00:00
..
black_compatibility@conditional_expression.py.snap Format expr generator exp (#5804) 2023-07-19 13:01:58 +02:00
black_compatibility@miscellaneous__blackd_diff.py.snap Update Black tests (#5438) 2023-06-30 06:32:50 +00:00
black_compatibility@miscellaneous__debug_visitor.py.snap format ExprJoinedStr (#5932) 2023-08-01 08:26:30 +02:00
black_compatibility@miscellaneous__decorators.py.snap Format ExpressionStarred nodes (#5654) 2023-07-11 06:08:08 +00:00
black_compatibility@miscellaneous__docstring_no_string_normalization.py.snap Update Black tests (#5438) 2023-06-30 06:32:50 +00:00
black_compatibility@miscellaneous__docstring_preview_no_string_normalization.py.snap format ExprJoinedStr (#5932) 2023-08-01 08:26:30 +02:00
black_compatibility@miscellaneous__force_pyi.py.snap Format target: annotation = value? expressions (#5661) 2023-07-11 16:40:28 +02:00
black_compatibility@miscellaneous__long_strings_flag_disabled.py.snap format ExprJoinedStr (#5932) 2023-08-01 08:26:30 +02:00
black_compatibility@miscellaneous__power_op_newline.py.snap Update Black tests (#5438) 2023-06-30 06:32:50 +00:00
black_compatibility@miscellaneous__string_quotes.py.snap format ExprJoinedStr (#5932) 2023-08-01 08:26:30 +02:00
black_compatibility@py_38__pep_570.py.snap Format lambda expression (#5806) 2023-07-19 11:47:56 +00:00
black_compatibility@py_39__pep_572_py39.py.snap Format SetComp (#5774) 2023-07-15 15:50:47 +01:00
black_compatibility@py_39__python39.py.snap Remove parentheses around some walrus operators (#6173) 2023-07-29 10:06:26 -04:00
black_compatibility@py_310__pattern_matching_complex.py.snap Add formatting for MatchCase (#6360) 2023-08-11 19:20:25 +05:30
black_compatibility@py_310__pattern_matching_extras.py.snap Add formatting for MatchCase (#6360) 2023-08-11 19:20:25 +05:30
black_compatibility@py_310__pattern_matching_generic.py.snap Add formatting for StmtMatch (#6286) 2023-08-08 18:48:49 +05:30
black_compatibility@py_310__pattern_matching_simple.py.snap Add formatting for MatchCase (#6360) 2023-08-11 19:20:25 +05:30
black_compatibility@py_310__pattern_matching_style.py.snap Add formatting for StmtMatch (#6286) 2023-08-08 18:48:49 +05:30
black_compatibility@py_310__pep_572_py310.py.snap Format expr generator exp (#5804) 2023-07-19 13:01:58 +02:00
black_compatibility@py_310__remove_newline_after_match.py.snap Add formatting for MatchCase (#6360) 2023-08-11 19:20:25 +05:30
black_compatibility@simple_cases__attribute_access_on_number_literals.py.snap Format numeric constants (#5972) 2023-07-24 07:04:40 +00:00
black_compatibility@simple_cases__comment_after_escaped_newline.py.snap Update Black tests (#5438) 2023-06-30 06:32:50 +00:00
black_compatibility@simple_cases__comments2.py.snap Format bytes string (#6166) 2023-07-31 10:46:40 +02:00
black_compatibility@simple_cases__comments6.py.snap Format ExpressionStarred nodes (#5654) 2023-07-11 06:08:08 +00:00
black_compatibility@simple_cases__comments9.py.snap Remove newline-insertion logic from JoinNodesBuilder (#6205) 2023-07-31 16:58:15 -04:00
black_compatibility@simple_cases__comments_non_breaking_space.py.snap Format import statements (#5493) 2023-07-04 07:07:20 +00:00
black_compatibility@simple_cases__composition.py.snap Mark trailing comments in parenthesized tests (#6287) 2023-08-03 20:45:03 +00:00
black_compatibility@simple_cases__composition_no_trailing_comma.py.snap Mark trailing comments in parenthesized tests (#6287) 2023-08-03 20:45:03 +00:00
black_compatibility@simple_cases__docstring.py.snap Update Black tests (#5438) 2023-06-30 06:32:50 +00:00
black_compatibility@simple_cases__docstring_preview.py.snap format ExprJoinedStr (#5932) 2023-08-01 08:26:30 +02:00
black_compatibility@simple_cases__empty_lines.py.snap format ExprJoinedStr (#5932) 2023-08-01 08:26:30 +02:00
black_compatibility@simple_cases__expression.py.snap Call chain formatting in fluent style (#6151) 2023-08-04 13:58:01 +00:00
black_compatibility@simple_cases__fmtonoff.py.snap Call chain formatting in fluent style (#6151) 2023-08-04 13:58:01 +00:00
black_compatibility@simple_cases__fmtonoff2.py.snap Format assert statement (#5168) 2023-07-14 09:01:33 +02:00
black_compatibility@simple_cases__fmtonoff3.py.snap Update Black tests (#5438) 2023-06-30 06:32:50 +00:00
black_compatibility@simple_cases__fmtonoff4.py.snap Don't add a magic trailing comma for a single entry (#5463) 2023-07-03 21:48:44 +02:00
black_compatibility@simple_cases__fmtonoff5.py.snap Pass parent to NeedsParentheses (#5708) 2023-07-13 08:57:29 +02:00
black_compatibility@simple_cases__fmtskip.py.snap Update Black tests (#5438) 2023-06-30 06:32:50 +00:00
black_compatibility@simple_cases__fmtskip2.py.snap Update Black tests (#5438) 2023-06-30 06:32:50 +00:00
black_compatibility@simple_cases__fmtskip3.py.snap Update Black tests (#5438) 2023-06-30 06:32:50 +00:00
black_compatibility@simple_cases__fmtskip5.py.snap Improve comprehension line break beheavior 2023-07-11 16:51:24 +02:00
black_compatibility@simple_cases__fmtskip7.py.snap Update Black tests (#5438) 2023-06-30 06:32:50 +00:00
black_compatibility@simple_cases__fmtskip8.py.snap Rewrite placement logic (#6040) 2023-07-26 16:21:23 +00:00
black_compatibility@simple_cases__function.py.snap Call chain formatting in fluent style (#6151) 2023-08-04 13:58:01 +00:00
black_compatibility@simple_cases__function2.py.snap Add empty lines before nested functions and classes (#6206) 2023-08-01 15:30:59 +00:00
black_compatibility@simple_cases__ignore_pyi.py.snap Rewrite placement logic (#6040) 2023-07-26 16:21:23 +00:00
black_compatibility@simple_cases__import_spacing.py.snap Format import statements (#5493) 2023-07-04 07:07:20 +00:00
black_compatibility@simple_cases__multiline_consecutive_open_parentheses_ignore.py.snap Expand parents whenever open-parenthesis comments are present (#6389) 2023-08-08 08:45:20 -04:00
black_compatibility@simple_cases__remove_await_parens.py.snap Format ExprYield/ExprYieldFrom (#5921) 2023-07-21 12:07:51 +00:00
black_compatibility@simple_cases__remove_except_parens.py.snap Format raise statement (#5595) 2023-07-10 21:23:49 +02:00
black_compatibility@simple_cases__remove_for_brackets.py.snap Format lambda expression (#5806) 2023-07-19 11:47:56 +00:00
black_compatibility@simple_cases__remove_parens.py.snap format ExprJoinedStr (#5932) 2023-08-01 08:26:30 +02:00
black_compatibility@simple_cases__return_annotation_brackets.py.snap Allow return type annotations to use their own parentheses (#6436) 2023-08-11 18:19:21 +00:00
black_compatibility@simple_cases__torture.py.snap Expand parents whenever open-parenthesis comments are present (#6389) 2023-08-08 08:45:20 -04:00
black_compatibility@simple_cases__trailing_comma_optional_parens3.py.snap Prefer expanding parenthesized expressions before operands 2023-07-11 14:07:39 +02:00
black_compatibility@simple_cases__trailing_commas_in_leading_parts.py.snap Format assert statement (#5168) 2023-07-14 09:01:33 +02:00
black_compatibility@simple_cases__tupleassign.py.snap Format bytes string (#6166) 2023-07-31 10:46:40 +02:00
black_compatibility@simple_cases__whitespace.py.snap Update Black tests (#5438) 2023-06-30 06:32:50 +00:00
format@carriage_return__string.py.snap Normalize '\r' in string literals to '\n' 2023-06-30 10:13:23 +02:00
format@expression__annotated_assign.py.snap Format target: annotation = value? expressions (#5661) 2023-07-11 16:40:28 +02:00
format@expression__attribute.py.snap Call chain formatting in fluent style (#6151) 2023-08-04 13:58:01 +00:00
format@expression__binary.py.snap Fix zulip unstable formatting with end-of-line comments (#6386) 2023-08-08 09:15:35 +00:00
format@expression__binary_implicit_string.py.snap Fix formatting of chained boolean operations (#6394) 2023-08-07 12:22:33 -05:00
format@expression__boolean_operation.py.snap Fix formatting of chained boolean operations (#6394) 2023-08-07 12:22:33 -05:00
format@expression__bytes.py.snap Format bytes string (#6166) 2023-07-31 10:46:40 +02:00
format@expression__call.py.snap Expand parents whenever open-parenthesis comments are present (#6389) 2023-08-08 08:45:20 -04:00
format@expression__compare.py.snap Avoid omitting optional parentheses for argument-less parentheses (#6484) 2023-08-11 17:58:42 +00:00
format@expression__dict.py.snap Fix zulip unstable formatting with end-of-line comments (#6386) 2023-08-08 09:15:35 +00:00
format@expression__dict_comp.py.snap Expand parents whenever open-parenthesis comments are present (#6389) 2023-08-08 08:45:20 -04:00
format@expression__fstring.py.snap move comments from expressions in f-strings out (#6481) 2023-08-11 09:22:30 +02:00
format@expression__generator_exp.py.snap Tweak breaking groups for comprehensions (#6321) 2023-08-04 14:00:54 +00:00
format@expression__if.py.snap Fix find_only_token_in_range with expression parentheses (#5645) 2023-07-10 15:55:19 +02:00
format@expression__lambda.py.snap Fix zulip unstable formatting with end-of-line comments (#6386) 2023-08-08 09:15:35 +00:00
format@expression__list.py.snap Expand parents whenever open-parenthesis comments are present (#6389) 2023-08-08 08:45:20 -04:00
format@expression__list_comp.py.snap Tweak breaking groups for comprehensions (#6321) 2023-08-04 14:00:54 +00:00
format@expression__named_expr.py.snap Force parentheses for named expressions in more contexts (#6494) 2023-08-11 01:54:46 -04:00
format@expression__set_comp.py.snap Avoid line break before for in comprehension if outer expression expands (#5912) 2023-07-20 10:07:22 +00:00
format@expression__slice.py.snap Improve slice formatting (#5922) 2023-07-20 15:05:18 +00:00
format@expression__split_empty_brackets.py.snap Avoid omitting optional parentheses for argument-less parentheses (#6484) 2023-08-11 17:58:42 +00:00
format@expression__starred.py.snap Placement refactor (#6034) 2023-07-25 11:49:05 +02:00
format@expression__string.py.snap Fix formatting of trailing unescaped quotes in raw triple quoted strings (#6202) 2023-07-31 19:25:16 +02:00
format@expression__tuple.py.snap Generalize comment-after-bracket handling to lists, sets, etc. (#6320) 2023-08-04 01:28:05 +00:00
format@expression__unary.py.snap Prefer expanding parenthesized expressions before operands 2023-07-11 14:07:39 +02:00
format@expression__yield.py.snap Format ExprYield/ExprYieldFrom (#5921) 2023-07-21 12:07:51 +00:00
format@expression__yield_from.py.snap Format ExprYield/ExprYieldFrom (#5921) 2023-07-21 12:07:51 +00:00
format@parentheses__call_chains.py.snap Avoid breaking call chains unnecessarily (#6488) 2023-08-11 13:33:15 +00:00
format@parentheses__nested.py.snap Formatter: Add test cases for comments after opening parentheses (#6420) 2023-08-10 08:34:03 +00:00
format@parentheses__opening_parentheses_comment_empty.py.snap Formatter: Add test cases for comments after opening parentheses (#6420) 2023-08-10 08:34:03 +00:00
format@parentheses__opening_parentheses_comment_value.py.snap Formatter: Add test cases for comments after opening parentheses (#6420) 2023-08-10 08:34:03 +00:00
format@skip_magic_trailing_comma.py.snap Don't format trailing comma for lambda arguments (#5946) 2023-07-27 10:22:13 -04:00
format@statement__ann_assign.py.snap Fix StmtAnnAssign formatting by mirroring StmtAssign (#5732) 2023-07-13 10:51:25 +00:00
format@statement__assert.py.snap Format assert statement (#5168) 2023-07-14 09:01:33 +02:00
format@statement__assign.py.snap Avoid omitting optional parentheses for argument-less parentheses (#6484) 2023-08-11 17:58:42 +00:00
format@statement__aug_assign.py.snap Fix StmtAnnAssign formatting by mirroring StmtAssign (#5732) 2023-07-13 10:51:25 +00:00
format@statement__break.py.snap Add tests for skip magic trailing comma 2023-06-26 14:15:55 +02:00
format@statement__class_definition.py.snap Add formatting of type parameters in class and function definitions (#6161) 2023-08-02 20:29:28 +00:00
format@statement__delete.py.snap Fix zulip unstable formatting with end-of-line comments (#6386) 2023-08-08 09:15:35 +00:00
format@statement__for.py.snap Pass parent to NeedsParentheses (#5708) 2023-07-13 08:57:29 +02:00
format@statement__function.py.snap Allow return type annotations to use their own parentheses (#6436) 2023-08-11 18:19:21 +00:00
format@statement__global.py.snap Break global and nonlocal statements over continuation lines (#6172) 2023-08-02 19:55:00 +00:00
format@statement__if.py.snap Fix formatter instability with half-indented comment (#6460) 2023-08-11 11:21:16 +00:00
format@statement__import.py.snap Format import statements (#5493) 2023-07-04 07:07:20 +00:00
format@statement__import_from.py.snap Preserve end-of-line comments on import-from statements (#6216) 2023-08-01 18:58:05 +00:00
format@statement__match.py.snap Add formatting for MatchCase (#6360) 2023-08-11 19:20:25 +05:30
format@statement__nonlocal.py.snap Break global and nonlocal statements over continuation lines (#6172) 2023-08-02 19:55:00 +00:00
format@statement__raise.py.snap Fix zulip unstable formatting with end-of-line comments (#6386) 2023-08-08 09:15:35 +00:00
format@statement__return_annotation.py.snap Allow return type annotations to use their own parentheses (#6436) 2023-08-11 18:19:21 +00:00
format@statement__try.py.snap Mark trailing comments in parenthesized tests (#6287) 2023-08-03 20:45:03 +00:00
format@statement__type_alias.py.snap Add formatting of type alias statements (#6162) 2023-08-02 20:40:32 +00:00
format@statement__while.py.snap Pass parent to NeedsParentheses (#5708) 2023-07-13 08:57:29 +02:00
format@statement__with.py.snap Fix formatter with-statement after-as own line comment instability (#6033) 2023-07-24 18:12:07 +00:00
format@trivia.py.snap Add tests for skip magic trailing comma 2023-06-26 14:15:55 +02:00