-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Conversation
7aa643e
to
2cc26f5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
tests/data/python38.py
Outdated
# 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 |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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
There was a problem hiding this 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.
2cc26f5
to
c195d3e
Compare
Thanks @hauntsaninja for reviewing; yep I intended this to be a backport of python/cpython@8565f6b and python/cpython@62c35a8. |
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!