Skip to content

Add install_types to OPTIONS_AFFECTING_CACHE#21070

Open
brianschubert wants to merge 1 commit intopython:masterfrom
brianschubert:cache-install-types
Open

Add install_types to OPTIONS_AFFECTING_CACHE#21070
brianschubert wants to merge 1 commit intopython:masterfrom
brianschubert:cache-install-types

Conversation

@brianschubert
Copy link
Collaborator

Noticed in #21068

Invalidate the cache when --install-types changes so that previous runs without --install-types don't prevent stub packages from being installed.

Before (note: no install attempt in second invocation)

$ echo 'import pygments' > file.py

$ python3 -m mypy  ./file.py
file.py:1: error: Library stubs not installed for "pygments.lexers"  [import-untyped]
file.py:1: note: Hint: "python3 -m pip install types-Pygments"
file.py:1: note: (or run "mypy --install-types" to install all missing stub packages)
file.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
file.py:1: error: Library stubs not installed for "pygments"  [import-untyped]
Found 2 errors in 1 file (checked 1 source file)

$ python3 -m mypy --install-types --non-interactive ./file.py                  
file.py:1: error: Library stubs not installed for "pygments.lexers"  [import-untyped]
file.py:1: note: Hint: "python3 -m pip install types-Pygments"
file.py:1: note: (or run "mypy --install-types" to install all missing stub packages)
file.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
file.py:1: error: Library stubs not installed for "pygments"  [import-untyped]
Found 2 errors in 1 file (checked 1 source file)

After (note: install in second invocation)

$ echo 'import pygments' > file.py

$ python3 -m mypy  ./file.py
file.py:1: error: Library stubs not installed for "pygments.lexers"  [import-untyped]
file.py:1: note: Hint: "python3 -m pip install types-Pygments"
file.py:1: note: (or run "mypy --install-types" to install all missing stub packages)
file.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
file.py:1: error: Library stubs not installed for "pygments"  [import-untyped]
Found 2 errors in 1 file (checked 1 source file)

$ python3 -m mypy --install-types --non-interactive ./file.py                  
Installing missing stub packages:
[...]/.temp_venv/bin/python3 -m pip install types-Pygments

Collecting types-Pygments
  Using cached types_pygments-2.19.0.20251121-py3-none-any.whl.metadata (2.0 kB)
Requirement already satisfied: types-docutils in ./.temp_venv/lib/python3.13/site-packages (from types-Pygments) (0.22.3.20260322)
Using cached types_pygments-2.19.0.20251121-py3-none-any.whl (25 kB)
Installing collected packages: types-Pygments
Successfully installed types-Pygments-2.19.0.20251121

[notice] A new release of pip is available: 25.3 -> 26.0.1
[notice] To update, run: pip install --upgrade pip

Success: no issues found in 1 source file

@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant