Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop changing return type annotations to tuples #2384

Merged
merged 7 commits into from Aug 26, 2021

Conversation

ichard26
Copy link
Collaborator

Fixes #2381.


This fixes a bug where a trailing comma would be added to a
parenthesized return type annotation changing its type to a tuple.
Here's one case where this bug shows up:

def spam() -> (
    this_is_a_long_type_annotation_which_should_NOT_get_a_trailing_comma
):
    pass

The root problem was that the type annotation was treated as if it was
a collection (is_body=True to linegen::bracket_split_build_line) where
a trailing comma is usually fine. Now there's another check in the
aforementioned function to make sure the body it's operating on isn't
a parenthesized return type annotation before truly adding a trailing
comma.

@JelleZijlstra
Copy link
Collaborator

Great find! I wonder if there are other syntactic contexts where this can happen, maybe a with statement on a really long variable name?

@ichard26 ichard26 marked this pull request as draft July 20, 2021 04:05
This fixes a bug where a trailing comma would be added to a
parenthesized return annotation changing its type to a tuple.
Here's one case where this bug shows up:

```
def spam() -> (
    this_is_a_long_type_annotation_which_should_NOT_get_a_trailing_comma
):
    pass
```

The root problem was that the type annotation was treated as if it was
a parameter & import list (is_body=True to linegen::bracket_split_build_line)
where a trailing comma is usually fine. Now there's another check in the
aforementioned function to make sure the body it's operating on isn't
a return annotation before truly adding a trailing comma.
@ichard26 ichard26 force-pushed the no-changing-type-annotation-to-tuple branch from 43ed104 to 99bceb1 Compare July 30, 2021 23:58
@ichard26 ichard26 marked this pull request as ready for review July 31, 2021 01:38
@ichard26
Copy link
Collaborator Author

Ping! I'd appreciate some attention on this ^^

@ichard26 ichard26 force-pushed the no-changing-type-annotation-to-tuple branch from ff23d57 to b651b64 Compare August 25, 2021 00:04
@JelleZijlstra JelleZijlstra merged commit 8a59528 into psf:main Aug 26, 2021
@ichard26 ichard26 deleted the no-changing-type-annotation-to-tuple branch July 28, 2022 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Internal Error when formatting bracketed return annotations
2 participants