Bug Report
I have mypy installed inside of a virtualenv. To my surprise, mypy looked for modules outside of the virtualenv. It appears that this is the section of code responsible:
https://github.com/python/mypy/blob/a1863c90/mypy/pyinfo.py#L27-L29
The docs for site.getusersitepackages() say this:
To determine if the user-specific site-packages was added to sys.path ENABLE_USER_SITE should be used.
From my reading, the code section linked to above should check site.ENABLE_USER_SITE before adding site.getusersitepackages() to the returned list of paths.
As a workaround, I found that I can set PYTHONUSERBASE to some non-existent path, so that mypy won't look in a valid directory.
To Reproduce
-
Install mypy in virtualenv
-
Install package outside of virtualenv, e.g. pip install --user types-PyYaml
-
Run mypy foo/
-
Notice that mypy doesn't complain about missing stubs for PyYaml package
-
mypy -v also has this line of output:
LOG: Metadata fresh for yaml.dumper: file /home/knkski/.local/lib/python3.9/site-packages/yaml-stubs/dumper.pyi
Expected Behavior
mypy inside virtualenv would not look outside of the virtualenv for any packages
Actual Behavior
mypy inside virtualenv looked inside system user site packages folder
Your Environment
- Mypy version used: 0.910
- Mypy command-line flags:
mypy foo/
- Mypy configuration options from
mypy.ini (and other config files): N/A
- Python version used: 3.9.5
- Operating system and version: Ubuntu 21.04
Bug Report
I have mypy installed inside of a virtualenv. To my surprise, mypy looked for modules outside of the virtualenv. It appears that this is the section of code responsible:
https://github.com/python/mypy/blob/a1863c90/mypy/pyinfo.py#L27-L29
The docs for site.getusersitepackages() say this:
From my reading, the code section linked to above should check
site.ENABLE_USER_SITEbefore addingsite.getusersitepackages()to the returned list of paths.As a workaround, I found that I can set
PYTHONUSERBASEto some non-existent path, so that mypy won't look in a valid directory.To Reproduce
Install mypy in virtualenv
Install package outside of virtualenv, e.g.
pip install --user types-PyYamlRun
mypy foo/Notice that mypy doesn't complain about missing stubs for
PyYamlpackagemypy -valso has this line of output:Expected Behavior
mypy inside virtualenv would not look outside of the virtualenv for any packages
Actual Behavior
mypy inside virtualenv looked inside system user site packages folder
Your Environment
mypy foo/mypy.ini(and other config files): N/A