Skip to content

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

@gakugaku

Description

@gakugaku

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:

  1. 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"]
  2. Install dependencies and create a virtual environment:
    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

$ 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:
    [tool.mypy]
    strict = true
    # plugins = ["pydantic.mypy"]
    However, this removes the enhanced type checking that pydantic's mypy plugin provides.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue identified by VS Code Team member as probable bugtriage-needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions