microsoft / microsoft/vscode-mypy

Error importing plugin "pydantic.mypy": cannot import name 'Sentinel' from 'typing_extensions'

Open
#380 4 comments 10 reactions 0 assignees View on GitHub
bug triage-needed
Dominant language
Python
Stars
150
Forks
39
Avg merge
21h 45m
Merged PRs (30d)
8

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](https://github.com/python/typing_extensions/releases/tag/4.14.0)).

## Reproduction Steps:
1. Create a Python project with the following `pyproject.toml`:
```toml
[project]
dependencies = [
"pydantic>=2.12.4",
]

[dependency-groups]
dev = [
"mypy>=1.18.0",
]

[tool.mypy]
strict = true
plugins = ["pydantic.mypy"]
```
2. Install dependencies and create a virtual environment:
```bash
uv sync
```
3. Open any Python file in the project that uses pydantic models.
4. 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**

```bash
$ uv run mypy .
Success: no issues found in 27 source files
```

The 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 `uv` as package manager with `pyproject.toml`
* Mypy configuration: In `pyproject.toml` under `[tool.mypy]`
* Workaround: Commenting out the `pydantic.mypy` plugin resolves the extension error:
```toml
[tool.mypy]
strict = true
# plugins = ["pydantic.mypy"]
```
However, this removes the enhanced type checking that pydantic's mypy plugin provides.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the VS Code extension setup and inspect the bundled library at bundled/libs/typing_extensions.py, using the reported pydantic.mypy configuration and the command-line comparison as reference. Verify the bundled typing_extensions version and confirm that the extension can load the plugin and type-check the sample project without the Sentinel import error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.