Skip to content

Conversation

@ichard26
Copy link
Collaborator

Fixes #1828.
Fixes #1189.

@zsol I would appreciate if you could review as this is my first time swimming in these waters, and therefore I have no idea what I am doing :D. Thanks in advance!

@ichard26 ichard26 requested a review from zsol November 21, 2020 23:56
@ichard26 ichard26 force-pushed the allow_same_rhs_expressions branch from 7aa643e to 2cc26f5 Compare November 21, 2020 23:58
Copy link
Collaborator

@zsol zsol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

# all right hand side expressions allowed in regular assignments are now also allowed in
# annotated assignments
a : Tuple[ str, int] = "1", 2
a: List [ str] = *x
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like technically this is a syntax error, but it's allowed in the cpython grammar. Black should probably not be used to validate syntax though, so it's probably fine :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's probably fine. As long we don't add parenthesizes to any of the above, the case of the following won't happen :)

  • invalid python
  • Black accepts it
  • Black generates valid python at the end

#921 (comment)

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks right to me too, it's the same change CPython made in https://bugs.python.org/issue35814 / matches what's in the last version of the non PEG parser.

@ichard26 ichard26 force-pushed the allow_same_rhs_expressions branch from 2cc26f5 to c195d3e Compare November 23, 2020 21:45
@ichard26
Copy link
Collaborator Author

Thanks @hauntsaninja for reviewing; yep I intended this to be a backport of python/cpython@8565f6b and python/cpython@62c35a8.

@zsol zsol merged commit 4d03716 into psf:master Nov 24, 2020
@ichard26 ichard26 deleted the allow_same_rhs_expressions branch November 27, 2020 00:51
noxan pushed a commit to noxan/black that referenced this pull request Jun 6, 2021
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.

Can't format a yield expression with a type annotation and without parentheses Black crashes on annotated tuple assignment

3 participants