Thanks to visit codestin.com
Credit goes to github.com

Skip to content

mypy looks for modules outside of virtualenv #11274

Description

@knkski

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

  1. Install mypy in virtualenv

  2. Install package outside of virtualenv, e.g. pip install --user types-PyYaml

  3. Run mypy foo/

  4. Notice that mypy doesn't complain about missing stubs for PyYaml package

  5. 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions