Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Mypy does not find lone module .pyi stubs in site-packages #16987

@pwschaedler

Description

@pwschaedler

Bug Report

Mypy does not seem to resolve modules that consist of single-file .pyi files that sit directly in site-packages.

For example, the project pyodbc compiles to a single compiled module file, and its accompanying stub file sits with it in site-packages. However, mypy does not recognize this lone .pyi file and instead throws 'Cannot find implementation or library stub for module named "pyodbc" [import-not-found]'.

To Reproduce

python -m venv .venv
source .venv/bin/activate
pip install mypy==1.8.0 pyodbc==5.1.0
mypy -c 'import pyodbc'

Expected Behavior

I expect mypy to recognize the module in the same way Python does.

Actual Behavior

<string>:1: error: Cannot find implementation or library stub for module named "pyodbc"  [import-not-found]
<string>:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.8.0
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.10.12
$ ls .venv/lib/python3.10/site-packages
_distutils_hack       mypy_extensions-1.0.0.dist-info  __pycache__                  tomli                                                        distutils-precedence.pth                typing_extensions.py
mypy                  pip                              pyodbc-5.1.0.dist-info       tomli-2.0.1.dist-info                                        mypy_extensions.py
mypy-1.8.0.dist-info  pip-23.0.1.dist-info             setuptools                   typing_extensions-4.10.0.dist-info                           pyodbc.cpython-310-x86_64-linux-gnu.so
mypyc                 pkg_resources                    setuptools-65.5.0.dist-info  6c7190bc8b55ffe67f57__mypyc.cpython-310-x86_64-linux-gnu.so  pyodbc.pyi

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions