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
Syntax quirk with variable annotations #79995
Comments
Am not sure how much we care about this, but parenthesis around tuples stops being optional when there is a variable annotation. >>> from typing import Tuple
>>> t = 10, 'hello' # Parens not normally required
>>> t: Tuple[int, str] = (10, 'hello') # Annotated allows parens
>>> t: Tuple[int, str] = 10, 'hello' # Annotated w/o parens fails
SyntaxError: invalid syntax |
Good catch! I think it was just overlooked rather than a conscious decision (unlike the left hand side, that generated lots of debates) I will make a PR to allow everything that is allowed on r.h.s. of a normal assignment. |
I think PEP-526 does not clarify the intention here. Perhaps we could add a specific example? It currently shows: t: Tuple[int, ...] = (1, 2, 3) We could just add this there: t: Tuple[int, ...] = 1, 2, 3 |
(With a comment indicating that the second is only accepted in Python 3.8 and later.) |
Is PEP the best place for such updates? Maybe we can add a |
We should definitely update the docs, with But we should also update the PEP, because the reason this was changed was an interpretation issue in the PEP. This is different from simply changing things in a later version because we've come up with a new idea or we've learned that something was a bad idea. Now that the intention of the PEP has been clarified, the PEP itself ought to be updated with words expressing the clearer version; but because previously the intended syntax wasn't supported, it makes sense to also add a note there that this wasn't implemented correctly until 3.8. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: