`mypy` breaks when installed with `pip install --prefix`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
Let me introduce some shorthand notation for the sake of clarity. Let V be a virtual environment, Vsp the site-packages location within V, P a prefix path and Psp the site-packages location within P.
Now suppose that mypy is installed in P with pip install --prefix P mypy from within V. When invoking mypy from V, with mypy --install-types, the missing types are installed in Vsp, and this leads to errors of the kind
tests/test_unit.py:12: error: Untyped decorator makes function "current_interpreter" untyped
tests/test_unit.py:17: error: Untyped decorator makes function "current_venv" untyped
tests/test_integration.py:39: error: Untyped decorator makes function "tmp_run" untyped
tests/test_cli.py:18: error: Untyped decorator makes function "cli" untyped
tests/test_cli.py:273: error: Untyped decorator makes function "test_run_suites_cmdargs" untyped
Found 5 errors in 3 files (checked 10 source files)
(note that when mypy is installed in V rather than in P, no errors are reported, as expected). Setting MYPYPATH to include Vsp gives
.riot/venv_py394/lib/python3.9/site-packages is in the MYPYPATH. Please remove it.
See https://mypy.readthedocs.io/en/stable/running_mypy.html#how-mypy-handles-imports for more info
which is documented behaviour. Installing the missing types by hand in P from V with pip install --prefix type-... doesn't help:
riot/cli.py:9: error: Library stubs not installed for "pkg_resources" (or incompatible with Python 3.9)
riot/cli.py:9: note: Hint: "python3 -m pip install types-setuptools"
riot/cli.py:9: note: (or run "mypy --install-types" to install all missing stub packages)
riot/cli.py:9: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Setting MYPYPATH to include Psp gives
mypy: ".riot/venv_py394_types-mock_types-setuptools_mypy_pytest/lib/python3.9/site-packages/typing_extensions.py" shadows library module "typing_extensions"
note: A user-defined top-level module with name "typing_extensions" is not supported
So there doesn't seem to be a way to install mypy in a prefix
To Reproduce
See the above description of the issue
Expected Behavior
I would expect mypy to work even if I'd have to set MYPYPATH to something
Actual Behavior
No possible way of using mypy from a custom prefix.
Your Environment
- Mypy version used: 0.910
- Mypy command-line flags:
--install-types --non-interactive - Mypy configuration options from
mypy.ini(and other config files):
[mypy]
ignore_missing_imports = true
disallow_incomplete_defs = true
disallow_untyped_decorators = true
warn_unused_ignores = true
warn_unused_configs = true
disallow_any_generics = true
warn_redundant_casts = true
warn_return_any = true
strict_equality = true
no_implicit_optional = true
files = riot,tests
- Python version used: 3.9
- Operating system and version: macOS Big Sur
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
First reproduce the issue with pip install --prefix P mypy inside a virtual environment, then run mypy --install-types --non-interactive against the reported configuration. Trace how the CLI resolves the environment and site-packages paths for the custom prefix. Done means mypy can install and use missing types from a custom prefix without the reported import or shadowing errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100