-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Tuple assignment and list * unpacking crashes mypy #3825
Comments
Based on |
(Bumping priority to high since this appeared again in the context of mypyc) |
I think the cop-out way to fix this would be to have |
I came across this error when working on #7779. I think both issues will be fixed by the same solution. @refi64 I don't think getting the index of the starred expression will work the same as it does for lvalues, because the star does really different things on an lvalue vs an rvalue, and there can be more than one: a = (1, 2, 3)
first, *other = *a, 4 # mypy: crash
print(other) # python: [2, 3, 4]
first, *other = *(*a, 4), 5 # mypy: crash
print(other) # python: [2, 3, 4, 5]
first, *other = *a, *a # mypy: crash
print(other) # python: [2, 3, 1, 2, 3] |
Another similar looking example reported in #8635: a, b = *(1, 2) |
This ends up in an internal error too: a, b = *(1,), *(2,) Maybe it would be useful to add this one too to future tests to be completely sure. (Just ran into this issue for the first time and ended up with this version. Good luck brave fixers!) |
Just ran into this issue on 0.8.12 trying to do essentially this: tup = (1, (2, 3))
a, b = *tup Looks like flake8 does not pick up on this being a syntax error. |
In general, mypy doesn't promise to be able to check the remainder of your code in the presence of syntax errors, so just make this a blocking error. Fixes python#9137 Fixes python#3825 (most of the reports in this issue were fixed by python#8827)
And |
Ran mypy over the following code:
Interestingly enough,
first, *other = [None, *a]
works correctly. Happy to give it a shot at fixing this myself is someone can give me some pointers on where to start.Exception:
The text was updated successfully, but these errors were encountered: