Skip to content
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

PYTHONPATH is corrupted by bundled dependencies dir in mypy process when using mypy-type-checker.path #217

Open
edwardpeek-crown-public opened this issue Nov 10, 2023 · 2 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug needs PR

Comments

@edwardpeek-crown-public

When mypy-type-checker.path is configured to use a user-controlled version of mypy instead of the bundled one, it is invoked with the PYTHONPATH env var set to include the extension's bundled python dependencies which causes mypy to return unexpected results as it loads dependencies from the bundled libs in preference to venv or system equivalents.

Configuring this setting with a shell stub to print environment such as

#!/bin/sh
env | sort 1>&2
exec ./venv/bin/mypy "$@"

reveals

PYTHONPATH=<redacted>/.vscode/extensions/ms-python.mypy-type-checker-2023.6.0/bundled/libs:

in the extension's output panel.

The extension setting importStrategy=fromEnvironment is affected by a similar bug: microsoft/vscode-black-formatter#369

The other VS Code extensions for black, isort, pylint do not set PYTHONPATH and so are correctly isolated from the LSP server python environment.

@karthiknadig
Copy link
Member

We need to add a check to verify that the mypy provided via path succeeds. If not, then we can leave an error log. Attempting fallback with PYTHONPATH can lead to same problem of loading packages from the wrong place.

@karthiknadig karthiknadig added bug Issue identified by VS Code Team member as probable bug needs PR and removed triage-needed labels Nov 17, 2023
@edwardpeek-crown-public
Copy link
Author

FWIW this issue can be worked around by VS Code settings similar to:

  "mypy-type-checker.path": [
    // Workaround for https://github.com/microsoft/vscode-mypy/issues/217
    "/usr/bin/env",
    "--unset=PYTHONPATH",
    "${workspaceFolder}/.venv/bin/mypy",
  ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug needs PR
Projects
None yet
Development

No branches or pull requests

2 participants