-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Type error in mypy? #2222
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
Comments
Error messages about the source:
|
The type of the variable |
So, what should happen in the code? |
The |
Ok that makes sense |
Is there an action item here? Can you update the topic to reflect that? Else please close. |
There is, and it is fixed in #2238. |
If you sent a separate PR that just fixed that it would be quicker to review. |
Plus it boosts your commit count :) |
It just happens to be required for the PR I actually wanted. |
During #2221 (which I have little hope to be actually accepted) I ran into this function in binder.py:
The Var case comes from
analyze_var_ref()
in checkexpr.py.Well, I couldn't find where Var.literal_hash is initialized to anything other than None, and returning None in the Var case passes all the tests. So I tried to replace it with something like the following:
I then ran mypy on itself, but it raised many errors. So I ran the test suite, and I got many failures; however, it seems that these failures are due to a more precise typechecking. For example, take testModifyLoopFor4 (simplified):
The test does not say anything bad in this part, but mypy now complains that x is an int and therefore 'a' cannot be assigned into it. It might be too restrictive, but it is my understanding that this is the desired behavior, since "x=1" rebinds the variable into int (it's valid since int is part of the Union) and then it tries to rebind it to str, but now it is not possible.
I am not 100% sure, since I am not 100% sure how the code works and what is the expected behavior, but it looks like a bug - and if so, there are ~40 "type errors" to fix in the source code (although I suspect none of them is an actual error).
So what is the expected behavior? When and how should types rebind?
The text was updated successfully, but these errors were encountered: