-
Notifications
You must be signed in to change notification settings - Fork 36
Description
Diagnostic Data
- Python version (& distribution if applicable, e.g., Anaconda): Python 3.14.0 (standard CPython)
- Type of virtual environment used (e.g., conda, venv, virtualenv, etc.): venv (managed by uv)
- Operating system (and version): Linux Ubuntu 24.04.2 LTS (in dev container)
- Version of tool extension you are using: ms-python.mypy-type-checker@2025.2.0
Behaviour
Expected Behavior
When using pydantic.mypy plugin in pyproject.toml, the mypy extension should load the plugin successfully and perform type checking with pydantic model validation, just as it does when running mypy from the command line.
Actual Behavior
The extension fails with the following error:
pyproject.toml:1:1:1:1: error: Error importing plugin "pydantic.mypy": cannot import name 'Sentinel' from 'typing_extensions' (/home/vscode/.vscode-server/extensions/ms-python.mypy-type-checker-2025.2.0/bundled/libs/typing_extensions.py) [misc]
The error indicates that the bundled typing_extensions in the extension is missing the Sentinel type, which is required by the pydantic.mypy plugin (added in typing_extensions 4.14.0).
Reproduction Steps:
- Create a Python project with the following
pyproject.toml:[project] dependencies = [ "pydantic>=2.12.4", ] [dependency-groups] dev = [ "mypy>=1.18.0", ] [tool.mypy] strict = true plugins = ["pydantic.mypy"]
- Install dependencies and create a virtual environment:
uv sync
- Open any Python file in the project that uses pydantic models.
- Observe the error in the mypy output panel.
Logs:
2025-11-07 09:58:17.371 [info] [Trace - 9:58:17 AM] Received notification 'window/logMessage'.
2025-11-07 09:58:17.371 [info] Params: {
"type": 4,
"message": "pyproject.toml: [mypy]: Unrecognized option: exclude_gitignore = True\npyproject.toml:1:1:1:1: error: Error importing plugin \"pydantic.mypy\": cannot import name 'Sentinel' from 'typing_extensions' (/home/vscode/.vscode-server/extensions/ms-python.mypy-type-checker-2025.2.0/bundled/libs/typing_extensions.py) [misc]\n"
}
2025-11-07 09:58:17.371 [info] pyproject.toml: [mypy]: Unrecognized option: exclude_gitignore = True
pyproject.toml:1:1:1:1: error: Error importing plugin "pydantic.mypy": cannot import name 'Sentinel' from 'typing_extensions' (/home/vscode/.vscode-server/extensions/ms-python.mypy-type-checker-2025.2.0/bundled/libs/typing_extensions.py) [misc]
Outcome When Attempting Debugging Steps:
Did running it from the command line work? YES
$ uv run mypy .
Success: no issues found in 27 source filesThe exact same configuration with plugins = ["pydantic.mypy"] works fine when running mypy 1.18.2 from the command line with pydantic 2.12.4 installed in the project's virtual environment.
This confirms the issue is specific to the VS Code extension's bundled libraries, not the mypy configuration or the project setup.
Extra Details
- Installed versions in project:
- mypy: 1.18.2
- pydantic: 2.12.4
- typing_extensions: 4.12.2
- VS Code: 1.105.1
- Project structure: Using
uvas package manager withpyproject.toml - Mypy configuration: In
pyproject.tomlunder[tool.mypy] - Workaround: Commenting out the
pydantic.mypyplugin resolves the extension error:However, this removes the enhanced type checking that pydantic's mypy plugin provides.[tool.mypy] strict = true # plugins = ["pydantic.mypy"]