-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Importing packages can poison the mypy
cache.
#5534
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
What do you get without |
@gvanrossum I have verified the behavior is the same without that flag. I will edit my repro case to remove the flag, since it is unrelated. |
OK, so then it would be interesting to see which part of aiohttp 3.4.0 causes the problem. That will be a difficult bisection job (remove code from aiohttp until the problem no longer occurs). But first, it's been over a month since mypy 0.620 was released, and the bugfix elves have been hard at work all that time. Does the problem still occur with mypy master from GitHub? |
As of the current latest on
in the original venv. |
Thanks for confirming -- then bisecting by removing large parts of aiohttp is in order... |
There is a hint in the traceback: the problematic type is aliased somewhere at a module level. This should narrow down the search area. |
Here is a minimalist repro: # file main.py
import lib
x = 1
# file lib.py
class Slow:
pass
s: Slow # could be anything that uses 'Slow' as a type: function, type alias, etc.
from cext import Slow # type: ignore Run And this is what is going on: first mypy creates an The best solution IMO is that import over an existing name should never shadow/overwrite an existing node in the symbol table. The original node should be the "wining" one. Later we can support conditional imports by creating a "union" of two nodes, but we have a separate issue for this. |
Another thing pointed out by @asvetlov is that the assert message could be a bit more informative. I will improve it as a part of the PR (just showing a full name and type of problematic node would be much better). |
Interesting. Thanks. |
thanks! |
Ok -- this is a weird one, but I think I've got it down to the smallest possible repro.
I first noticed this issue with the
aiohttp
library as of version3.4.0
(when they introduced type-hinting), but I'm cross-posting this issue to both projects since the issue seems to run deeper than just a library issue. Importing theaiohttp
library, even if it is unused, causes themypy
cache to occasionally get poisoned.Here's the repro case:
Running
python -m mypy repro.py
against this file works as expected (eg. returns an incompatible return type error). Replacing the-> dict
with-> str
throws the following assertion (attached at bottom of report) on re-running the type check. Note that this holds true in the opposite direction -- if we begin with-> str
, the first typecheck is successful, but replacing-> str
with-> dict
causes the same assertion error. Either way, the situation can only be resolved by clearing the.mypy_cache
folder, at which pointmypy
acts as expected once more.Interestingly, removing the
aiohttp
import prevents this poisoning from occurring. In addition, removing the import once the cache is poisoned also fixes the issue.I speculate there are two issues here, one with
aiohttp
and one withmypy
:aiohttp
seems to have some weirdness going on in their type hintingmypy
issues when dealing only with stdlib types.Error Trace:
Versions:
The text was updated successfully, but these errors were encountered: