Load config plugins from python executable paths#21653
Open
w-Jessamine wants to merge 2 commits into
Open
Conversation
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: django-modern-rest (https://github.com/wemake-services/django-modern-rest)
- pyproject.toml:1: error: Error importing plugin "pydantic.mypy": No module named 'pydantic' [misc]
+ dmr/validation/settings.py:29: error: Unused "type: ignore" comment [unused-ignore]
+ dmr/validation/settings.py:30: error: Unused "type: ignore" comment [unused-ignore]
+ dmr/validation/settings.py:31: error: Unused "type: ignore" comment [unused-ignore]
+ dmr/validation/settings.py:32: error: Unused "type: ignore" comment [unused-ignore]
+ dmr/validation/settings.py:33: error: Unused "type: ignore" comment [unused-ignore]
+ dmr/validation/settings.py:34: error: Unused "type: ignore" comment [unused-ignore]
+ dmr/validation/settings.py:35: error: Unused "type: ignore" comment [unused-ignore]
+ dmr/throttling/backends/redis.py:56: error: "Redis" expects no type arguments, but 1 given [type-arg]
+ dmr/throttling/backends/redis.py:158: error: "Redis" expects no type arguments, but 1 given [type-arg]
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This updates config plugin loading so module-name plugins can be imported from the search paths discovered for
--python-executable.Previously mypy used
--python-executableto discover imports from the target interpreter, but config plugins such aspydantic.mypywere still imported only from the current mypy processsys.path. As a result, globally installed mypy could type-check packages from a virtualenv while failing to load plugins installed in that same virtualenv.The new helper temporarily prepends the target interpreter's discovered
sys.pathand site-packages paths while loading config plugins, then restores the originalsys.path. It intentionally compares executable paths textually rather than withsamefile(), because a virtualenvbin/pythoncan resolve to the same underlying binary while still having different site-packages.Fixes #21621.
Tests
/tmp/mypy-pr-venv/bin/python -m pytest -n0 mypy/test/testplugins.py -q/tmp/mypy-pr-venv/bin/python -m pytest -n0 mypy/test/testargs.py mypy/test/testplugins.py -q/tmp/mypy-pr-venv/bin/python -m pytest -n0 mypy/test/testcheck.py::TypeCheckSuite::check-custom-plugin.test -q/tmp/mypy-pr-venv/bin/python -m mypy --config-file mypy_self_check.ini mypy/build.py mypy/test/testplugins.py/tmp/mypy-pr-venv/bin/python -m compileall -q mypy/build.py mypy/test/testplugins.pyDisclosure
I used an LLM coding assistant while investigating and preparing this change, and I reviewed and tested the resulting code.