Skip to content

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

Open

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.

Activity

  1. added
    bugIssue identified by VS Code Team member as probable bug
    on Nov 7, 2025
  2. vlad397 commented on Nov 11, 2025

    @vlad397

    Same problem. I found that if you delete "/.vscode-server/extensions/ms-python.mypy-type-checker-2025.2.0/bundled/libs/typing_extensions.py" everythins is working fine. Filename is conflicting with the library "typing_extensions". Ofc deleting is not a solution, just wanted to point it out.

    installed versions:

    fastapi==0.116.0 (for which you have pydantic==2.12.3)
    pydantic_settings==2.10.1
    mypy==1.18.2
    VS Code: 1.105.1
    
  3. alschall commented on Nov 28, 2025

    @alschall

    I noticed that the VSCode extension was loading a mypy version (1.15.0) that was different to the one in my env (1.18.2).

    Setting mypy-type-checker.importStrategy to env fixed it for me:

        "mypy-type-checker.importStrategy": "fromEnvironment",
    
  4. vlad397 commented on Dec 1, 2025

    @vlad397

    Albrecht Schall (@alschall) , nice! Helped me a lot

  5. ademoverflow commented on Dec 27, 2025

    @ademoverflow

    Albrecht Schall (@alschall) Thanks !! That helped a lot.

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

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