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

Allow same RHS expressions in annotated assignments as in regular assignments #1835

Merged
merged 1 commit into from Nov 24, 2020

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!

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
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
3 participants