Skip to content

Commit

Permalink
Fix crash in return annotation with walrus
Browse files Browse the repository at this point in the history
Fixes psf#3419
  • Loading branch information
JelleZijlstra committed Dec 10, 2022
1 parent 96e62c5 commit bae256b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -15,6 +15,7 @@
<!-- Changes that affect Black's preview style -->

- Fix a crash in preview style with assert + parenthesized string (#3415)
- Fix a crash in preview style with a walrus operator in a return annotation (#3422)

### Configuration

Expand Down
1 change: 1 addition & 0 deletions src/black/linegen.py
Expand Up @@ -1160,6 +1160,7 @@ def maybe_make_parens_invisible_in_atom(
syms.expr_stmt,
syms.assert_stmt,
syms.return_stmt,
syms.funcdef,
# these ones aren't useful to end users, but they do please fuzzers
syms.for_stmt,
syms.del_stmt,
Expand Down
9 changes: 9 additions & 0 deletions tests/data/preview/return_annotation_brackets.py
Expand Up @@ -91,6 +91,10 @@ def foo() -> tuple[int, int, int,]:
def frobnicate() -> "ThisIsTrulyUnreasonablyExtremelyLongClassName | list[ThisIsTrulyUnreasonablyExtremelyLongClassName]":
pass

# Should not remove parens around walrus operator
def walrus() -> (x := 1):
pass

# output
# Control
def double(a: int) -> int:
Expand Down Expand Up @@ -220,3 +224,8 @@ def frobnicate() -> (
" list[ThisIsTrulyUnreasonablyExtremelyLongClassName]"
):
pass


# Should not remove parens around walrus operator
def walrus() -> (x := 1):
pass

0 comments on commit bae256b

Please sign in to comment.