Skip to content

Mypy cannot find implementation if launched via the extension #363

@senhalil

Description

@senhalil

Diagnostic Data

  • Python version (& distribution if applicable, e.g., Anaconda): Python 3.11.11 (main, Dec 5 2024, 16:26:58) [Clang 16.0.0 (clang-1600.0.26.4)] on darwin
  • Type of virtual environment used (e.g., conda, venv, virtualenv, etc.): pants export
  • Operating system (and version): macOS 15.3.2 (24D81)
  • Version of tool extension you are using: ms-python.mypy-type-checker-2025.2.0

Behaviour

Expected Behavior

No [import-not-found] errors.

Actual Behavior

IDE displaying [import-not-found] errors.

Reproduction Steps:

We have a monorepo where the libraries reside under ./libraries/python which is covered by mypy_path in .mypy.pants.ini. The offending library foobar is under ./libraries/python/foobar/foobar (note the repeated foobar in the path). pants check and manual call to mypy (monorepo/.venv/bin/python -m mypy) works as expected (i.e., they don't report import errors.

I suspect the repeated foobar might be playing part in this because updating the mypy_path from
$MYPY_CONFIG_FILE_DIR/libraries/python,$MYPY_CONFIG_FILE_DIR/projects
to
$MYPY_CONFIG_FILE_DIR/libraries/python/foobar,$MYPY_CONFIG_FILE_DIR/libraries/python,$MYPY_CONFIG_FILE_DIR/projects
gets rid of the import errors the extension is reporting but this feels really hacky.

Logs:

While the extension outputs the following (with many [import-not-found] errors), calling the same command on the integrated terminal shows no errors.
2025-04-22 13:10:14.890 [info] Using cwd from `python.analysis.extraPaths`.
2025-04-22 13:10:14.891 [info] Server: Stop requested
2025-04-22 13:10:14.892 [debug] Server State: Stopped
2025-04-22 13:10:14.892 [info] [Trace - 1:10:14 PM] Sending request 'shutdown - (1)'.
2025-04-22 13:10:14.896 [info] [Trace - 1:10:14 PM] Received response 'shutdown - (1)' in 5ms.
2025-04-22 13:10:14.896 [info] No result returned.


2025-04-22 13:10:14.896 [info] [Trace - 1:10:14 PM] Sending notification 'exit'.
2025-04-22 13:10:14.896 [info] No parameters provided.


2025-04-22 13:10:14.899 [info] Using cwd from `python.analysis.extraPaths`.
2025-04-22 13:10:14.912 [info] Server run command: /Users/halilsen/monorepo/.venv/bin/python /Users/halilsen/.vscode/extensions/ms-python.mypy-type-checker-2025.2.0/bundled/tool/lsp_server.py
2025-04-22 13:10:14.912 [info] Server: Start requested.
2025-04-22 13:10:14.912 [debug] Server State: Starting
2025-04-22 13:10:15.277 [info] CWD Server: /Users/halilsen/monorepo
2025-04-22 13:10:15.278 [info] Settings used to run Server:
[
    {
        "cwd": "/Users/halilsen/monorepo",
        "workspace": "file:///Users/halilsen/monorepo",
        "args": [
            "--config-file=/Users/halilsen/monorepo/.mypy.pants.ini"
        ],
        "severity": {
            "error": "Error",
            "note": "Information"
        },
        "path": [],
        "ignorePatterns": [],
        "interpreter": [
            "/Users/halilsen/monorepo/.venv/bin/python"
        ],
        "importStrategy": "useBundled",
        "showNotifications": "off",
        "extraPaths": [
            "/Users/halilsen/monorepo/dist/codegen/libraries/proto"
        ],
        "reportingScope": "file",
        "preferDaemon": false,
        "daemonStatusFile": ""
    }
]

2025-04-22 13:10:15.278 [info] Global settings:
{
    "cwd": "${workspaceFolder}",
    "workspace": "/",
    "args": [],
    "severity": {
        "error": "Error",
        "note": "Information"
    },
    "path": [],
    "ignorePatterns": [],
    "interpreter": [],
    "importStrategy": "useBundled",
    "showNotifications": "off",
    "extraPaths": [],
    "reportingScope": "file",
    "preferDaemon": false,
    "daemonStatusFile": ""
}

2025-04-22 13:10:15.278 [info] sys.path used to run Server:
   /Users/halilsen/monorepo/dist/codegen/libraries/proto
   /Users/halilsen/monorepo
   /Users/halilsen/.vscode/extensions/ms-python.mypy-type-checker-2025.2.0/bundled/libs
   /Users/halilsen/.vscode/extensions/ms-python.mypy-type-checker-2025.2.0/bundled/tool
   /Users/halilsen/.pyenv/versions/3.11.11/lib/python311.zip
   /Users/halilsen/.pyenv/versions/3.11.11/lib/python3.11
   /Users/halilsen/.pyenv/versions/3.11.11/lib/python3.11/lib-dynload
   /Users/halilsen/monorepo/.venv/lib/python3.11/site-packages
2025-04-22 13:10:15.279 [info] /Users/halilsen/monorepo/.venv/bin/python -m mypy --version
2025-04-22 13:10:15.279 [info] CWD Server: /Users/halilsen/monorepo
2025-04-22 13:10:15.411 [info] 
mypy 1.15.0 (compiled: no)


2025-04-22 13:10:15.411 [info] Version info for linter running for /Users/halilsen/monorepo:
mypy 1.15.0 (compiled: no)

2025-04-22 13:10:15.411 [info] SUPPORTED mypy>=1.0.0
FOUND mypy==1.15.0

2025-04-22 13:10:15.414 [debug] Server State: Running
2025-04-22 13:10:15.418 [info] /Users/halilsen/.vscode/extensions/ms-python.mypy-type-checker-2025.2.0/bundled/tool/lsp_server.py:165: DeprecationWarning: 'workspace.get_document' has been deprecated, use 'workspace.get_text_document' instead
  document = LSP_SERVER.workspace.get_document(params.text_document.uri)

2025-04-22 13:10:15.418 [info] [Trace - 1:10:15 PM] Received notification 'window/logMessage'.
2025-04-22 13:10:15.418 [info] Params: {
    "type": 4,
    "message": "/Users/halilsen/monorepo/.venv/bin/python -m mypy --no-color-output --no-error-summary --show-absolute-path --show-column-numbers --show-error-codes --no-pretty --config-file=/Users/halilsen/monorepo/.mypy.pants.ini --show-error-end /Users/halilsen/monorepo/projects/qux/quux.py"
}


2025-04-22 13:10:15.418 [info] /Users/halilsen/monorepo/.venv/bin/python -m mypy --no-color-output --no-error-summary --show-absolute-path --show-column-numbers --show-error-codes --no-pretty --config-file=/Users/halilsen/monorepo/.mypy.pants.ini --show-error-end /Users/halilsen/monorepo/projects/qux/quux.py
2025-04-22 13:10:15.419 [info] [Trace - 1:10:15 PM] Received notification 'window/logMessage'.
2025-04-22 13:10:15.419 [info] Params: {
    "type": 4,
    "message": "CWD Server: /Users/halilsen/monorepo"
}


2025-04-22 13:10:15.419 [info] CWD Server: /Users/halilsen/monorepo
2025-04-22 13:10:24.525 [info] [Trace - 1:10:24 PM] Received notification 'window/logMessage'.
2025-04-22 13:10:24.525 [info] Params: {
    "type": 4,
    "message": "file:///Users/halilsen/monorepo/projects/qux/quux.py :\r\n/Users/halilsen/monorepo/projects/qux/quux.py:25:1:25:1: error: Cannot find implementation or library stub for module named \"foobar.convert\"  [import-not-found]\n/Users/halilsen/monorepo/projects/qux/quux.py:26:1:26:1: error: Cannot find implementation or library stub for module named \"foobar.interface\"  [import-not-found]\n/Users/halilsen/monorepo/projects/qux/quux.py:27:1:27:1: error: Cannot find implementation or library stub for module named \"foobar.interface.engine_interface\"  [import-not-found]\n/Users/halilsen/monorepo/projects/qux/quux.py:28:1:28:1: error: Cannot find implementation or library stub for module named \"foobar.interface.read_config\"  [import-not-found]\n/Users/halilsen/monorepo/projects/qux/quux.py:29:1:29:1: error: Cannot find implementation or library stub for module named \"foobar.src.config.policy_config\"  [import-not-found]\n/Users/halilsen/monorepo/projects/qux/quux.py:29:1:29:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports\n/Users/halilsen/monorepo/projects/qux/quux.py:30:1:30:1: error: Cannot find implementation or library stub for module named \"foobar.src.proto_wrappers.output\"  [import-not-found]\n/Users/halilsen/monorepo/projects/qux/quux.py:33:1:33:1: error: Cannot find implementation or library stub for module named \"foobar.src.proto_wrappers.run_request\"  [import-not-found]\n/Users/halilsen/monorepo/projects/qux/quux.py:36:1:36:1: error: Cannot find implementation or library stub for module named \"foobar.src.proto_wrappers.status\"  [import-not-found]\n/Users/halilsen/monorepo/projects/qux/quux.py:37:1:37:1: error: Cannot find implementation or library stub for module named \"foobar.src.proto_wrappers.input\"  [import-not-found]\n"
}


2025-04-22 13:10:24.525 [info] file:///Users/halilsen/monorepo/projects/qux/quux.py :
/Users/halilsen/monorepo/projects/qux/quux.py:25:1:25:1: error: Cannot find implementation or library stub for module named "foobar.convert"  [import-not-found]
/Users/halilsen/monorepo/projects/qux/quux.py:26:1:26:1: error: Cannot find implementation or library stub for module named "foobar.interface"  [import-not-found]
/Users/halilsen/monorepo/projects/qux/quux.py:27:1:27:1: error: Cannot find implementation or library stub for module named "foobar.interface.engine_interface"  [import-not-found]
/Users/halilsen/monorepo/projects/qux/quux.py:28:1:28:1: error: Cannot find implementation or library stub for module named "foobar.interface.read_config"  [import-not-found]
/Users/halilsen/monorepo/projects/qux/quux.py:29:1:29:1: error: Cannot find implementation or library stub for module named "foobar.src.config.policy_config"  [import-not-found]
/Users/halilsen/monorepo/projects/qux/quux.py:29:1:29:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
/Users/halilsen/monorepo/projects/qux/quux.py:30:1:30:1: error: Cannot find implementation or library stub for module named "foobar.src.proto_wrappers.output"  [import-not-found]
/Users/halilsen/monorepo/projects/qux/quux.py:33:1:33:1: error: Cannot find implementation or library stub for module named "foobar.src.proto_wrappers.run_request"  [import-not-found]
/Users/halilsen/monorepo/projects/qux/quux.py:36:1:36:1: error: Cannot find implementation or library stub for module named "foobar.src.proto_wrappers.status"  [import-not-found]
/Users/halilsen/monorepo/projects/qux/quux.py:37:1:37:1: error: Cannot find implementation or library stub for module named "foobar.src.proto_wrappers.input"  [import-not-found]

2025-04-22 13:10:24.525 [info] [Trace - 1:10:24 PM] Received notification 'window/logMessage'.
2025-04-22 13:10:24.525 [info] Params: {
    "type": 4,
    "message": "file:///Users/halilsen/monorepo/projects/qux/quux.py :\r\n/Users/halilsen/monorepo/projects/qux/quux.py:25:1:25:1: error: Cannot find implementation or library stub for module named \"foobar.convert\"  [import-not-found]\n/Users/halilsen/monorepo/projects/qux/quux.py:26:1:26:1: error: Cannot find implementation or library stub for module named \"foobar.interface\"  [import-not-found]\n/Users/halilsen/monorepo/projects/qux/quux.py:27:1:27:1: error: Cannot find implementation or library stub for module named \"foobar.interface.engine_interface\"  [import-not-found]\n/Users/halilsen/monorepo/projects/qux/quux.py:28:1:28:1: error: Cannot find implementation or library stub for module named \"foobar.interface.read_config\"  [import-not-found]\n/Users/halilsen/monorepo/projects/qux/quux.py:29:1:29:1: error: Cannot find implementation or library stub for module named \"foobar.src.config.policy_config\"  [import-not-found]\n/Users/halilsen/monorepo/projects/qux/quux.py:29:1:29:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports\n/Users/halilsen/monorepo/projects/qux/quux.py:30:1:30:1: error: Cannot find implementation or library stub for module named \"foobar.src.proto_wrappers.output\"  [import-not-found]\n/Users/halilsen/monorepo/projects/qux/quux.py:33:1:33:1: error: Cannot find implementation or library stub for module named \"foobar.src.proto_wrappers.run_request\"  [import-not-found]\n/Users/halilsen/monorepo/projects/qux/quux.py:36:1:36:1: error: Cannot find implementation or library stub for module named \"foobar.src.proto_wrappers.status\"  [import-not-found]\n/Users/halilsen/monorepo/projects/qux/quux.py:37:1:37:1: error: Cannot find implementation or library stub for module named \"foobar.src.proto_wrappers.input\"  [import-not-found]\n"
}


2025-04-22 13:10:24.525 [info] file:///Users/halilsen/monorepo/projects/qux/quux.py :
/Users/halilsen/monorepo/projects/qux/quux.py:25:1:25:1: error: Cannot find implementation or library stub for module named "foobar.convert"  [import-not-found]
/Users/halilsen/monorepo/projects/qux/quux.py:26:1:26:1: error: Cannot find implementation or library stub for module named "foobar.interface"  [import-not-found]
/Users/halilsen/monorepo/projects/qux/quux.py:27:1:27:1: error: Cannot find implementation or library stub for module named "foobar.interface.engine_interface"  [import-not-found]
/Users/halilsen/monorepo/projects/qux/quux.py:28:1:28:1: error: Cannot find implementation or library stub for module named "foobar.interface.read_config"  [import-not-found]
/Users/halilsen/monorepo/projects/qux/quux.py:29:1:29:1: error: Cannot find implementation or library stub for module named "foobar.src.config.policy_config"  [import-not-found]
/Users/halilsen/monorepo/projects/qux/quux.py:29:1:29:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
/Users/halilsen/monorepo/projects/qux/quux.py:30:1:30:1: error: Cannot find implementation or library stub for module named "foobar.src.proto_wrappers.output"  [import-not-found]
/Users/halilsen/monorepo/projects/qux/quux.py:33:1:33:1: error: Cannot find implementation or library stub for module named "foobar.src.proto_wrappers.run_request"  [import-not-found]
/Users/halilsen/monorepo/projects/qux/quux.py:36:1:36:1: error: Cannot find implementation or library stub for module named "foobar.src.proto_wrappers.status"  [import-not-found]
/Users/halilsen/monorepo/projects/qux/quux.py:37:1:37:1: error: Cannot find implementation or library stub for module named "foobar.src.proto_wrappers.input"  [import-not-found]

2025-04-22 13:10:24.527 [info] [Trace - 1:10:24 PM] Received notification 'textDocument/publishDiagnostics'.
2025-04-22 13:10:24.527 [info] Params: {
    "uri": "file:///Users/halilsen/monorepo/projects/qux/quux.py",
    "diagnostics": [
        {
            "range": {
                "start": {
                    "line": 24,
                    "character": 0
                },
                "end": {
                    "line": 24,
                    "character": 1
                }
            },
            "message": "Cannot find implementation or library stub for module named \"foobar.convert\"",
            "severity": 1,
            "code": "import-not-found",
            "codeDescription": {
                "href": "https://mypy.readthedocs.io/en/latest/_refs.html#code-import-not-found"
            },
            "source": "Mypy"
        },
        {
            "range": {
                "start": {
                    "line": 25,
                    "character": 0
                },
                "end": {
                    "line": 25,
                    "character": 1
                }
            },
            "message": "Cannot find implementation or library stub for module named \"foobar.interface\"",
            "severity": 1,
            "code": "import-not-found",
            "codeDescription": {
                "href": "https://mypy.readthedocs.io/en/latest/_refs.html#code-import-not-found"
            },
            "source": "Mypy"
        },
        {
            "range": {
                "start": {
                    "line": 26,
                    "character": 0
                },
                "end": {
                    "line": 26,
                    "character": 1
                }
            },
            "message": "Cannot find implementation or library stub for module named \"foobar.interface.engine_interface\"",
            "severity": 1,
            "code": "import-not-found",
            "codeDescription": {
                "href": "https://mypy.readthedocs.io/en/latest/_refs.html#code-import-not-found"
            },
            "source": "Mypy"
        },
        {
            "range": {
                "start": {
                    "line": 27,
                    "character": 0
                },
                "end": {
                    "line": 27,
                    "character": 1
                }
            },
            "message": "Cannot find implementation or library stub for module named \"foobar.interface.read_config\"",
            "severity": 1,
            "code": "import-not-found",
            "codeDescription": {
                "href": "https://mypy.readthedocs.io/en/latest/_refs.html#code-import-not-found"
            },
            "source": "Mypy"
        },
        {
            "range": {
                "start": {
                    "line": 28,
                    "character": 0
                },
                "end": {
                    "line": 28,
                    "character": 1
                }
            },
            "message": "Cannot find implementation or library stub for module named \"foobar.src.config.policy_config\"",
            "severity": 1,
            "code": "import-not-found",
            "codeDescription": {
                "href": "https://mypy.readthedocs.io/en/latest/_refs.html#code-import-not-found"
            },
            "source": "Mypy"
        },
        {
            "range": {
                "start": {
                    "line": 28,
                    "character": 0
                },
                "end": {
                    "line": 28,
                    "character": 1
                }
            },
            "message": "See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports",
            "severity": 3,
            "code": "note",
            "codeDescription": {
                "href": "https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports"
            },
            "source": "Mypy"
        },
        {
            "range": {
                "start": {
                    "line": 29,
                    "character": 0
                },
                "end": {
                    "line": 29,
                    "character": 1
                }
            },
            "message": "Cannot find implementation or library stub for module named \"foobar.src.proto_wrappers.output\"",
            "severity": 1,
            "code": "import-not-found",
            "codeDescription": {
                "href": "https://mypy.readthedocs.io/en/latest/_refs.html#code-import-not-found"
            },
            "source": "Mypy"
        },
        {
            "range": {
                "start": {
                    "line": 32,
                    "character": 0
                },
                "end": {
                    "line": 32,
                    "character": 1
                }
            },
            "message": "Cannot find implementation or library stub for module named \"foobar.src.proto_wrappers.run_request\"",
            "severity": 1,
            "code": "import-not-found",
            "codeDescription": {
                "href": "https://mypy.readthedocs.io/en/latest/_refs.html#code-import-not-found"
            },
            "source": "Mypy"
        },
        {
            "range": {
                "start": {
                    "line": 35,
                    "character": 0
                },
                "end": {
                    "line": 35,
                    "character": 1
                }
            },
            "message": "Cannot find implementation or library stub for module named \"foobar.src.proto_wrappers.status\"",
            "severity": 1,
            "code": "import-not-found",
            "codeDescription": {
                "href": "https://mypy.readthedocs.io/en/latest/_refs.html#code-import-not-found"
            },
            "source": "Mypy"
        },
        {
            "range": {
                "start": {
                    "line": 36,
                    "character": 0
                },
                "end": {
                    "line": 36,
                    "character": 1
                }
            },
            "message": "Cannot find implementation or library stub for module named \"foobar.src.proto_wrappers.input\"",
            "severity": 1,
            "code": "import-not-found",
            "codeDescription": {
                "href": "https://mypy.readthedocs.io/en/latest/_refs.html#code-import-not-found"
            },
            "source": "Mypy"
        }
    ]
}


Outcome When Attempting Debugging Steps:

Did running it from the command line work? Yes, calling the following command in the integrated terminal shows no errors
/Users/halilsen/monorepo/.venv/bin/python -m mypy --no-color-output --no-error-summary --show-absolute-path --show-column-numbers --show-error-codes --no-pretty --config-file=/Users/halilsen/monorepo/.mypy.pants.ini --show-error-end /Users/halilsen/monorepo/projects/qux/quux.py

Extra Details

Content of the "--config-file=/Users/halilsen/monorepo/.mypy.pants.ini"

[mypy]
explicit_package_bases = True
check_untyped_defs = True

# additional paths
mypy_path = $MYPY_CONFIG_FILE_DIR/libraries/python,$MYPY_CONFIG_FILE_DIR/projects

# Error message config
show_error_context = True
show_column_numbers = True
pretty = True
plugins = pandera.mypy, pydantic.mypy

Metadata

Metadata

Assignees

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