mypy-zope icon indicating copy to clipboard operation
mypy-zope copied to clipboard

mypy doesn't find stubs when on PYTHONPATH

Open jaraco opened this issue 4 years ago • 13 comments

Probably an upstream issue, but first encountered here, so reporting the details. Running a check on a file importing zope.interface will result in an error "Skipping analyzing zope.interface".

draft $ cat mypy.ini
[mypy]
plugins=mypy_zope:plugin
draft $ cat > interface.py
from zope.interface.interface import Interface

   
class X(Interface):
    pass
draft $ python -m venv venv
draft $ venv/bin/pip install -q mypy-zope
draft $ venv/bin/pip uninstall -q -y mypy-zope
draft $ venv/bin/pip install -q -t libs --no-deps mypy-zope
draft $ env PYTHONPATH=libs venv/bin/python -m mypy interface.py
interface.py:1: error: Skipping analyzing 'zope.interface.interface': found module but no type hints or library stubs
interface.py:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)

Even though the stubs are there:

draft $ tree libs/zope-stubs/
libs/zope-stubs/
├── __init__.pyi
├── interface
│   ├── __init__.pyi
│   ├── _compat.pyi
│   ├── _flatten.pyi
│   ├── _zope_interface_coptimizations.pyi
│   ├── adapter.pyi
│   ├── advice.pyi
│   ├── common
│   │   ├── __init__.pyi
│   │   ├── idatetime.pyi
│   │   ├── interfaces.pyi
│   │   ├── mapping.pyi
│   │   └── sequence.pyi
│   ├── declarations.pyi
│   ├── document.pyi
│   ├── exceptions.pyi
│   ├── interface.pyi
│   ├── interfaces.pyi
│   ├── registry.pyi
│   ├── ro.pyi
│   └── verify.pyi
└── schema
    ├── __init__.pyi
    ├── _bootstrapfields.pyi
    ├── _bootstrapinterfaces.pyi
    ├── _compat.pyi
    ├── _field.pyi
    ├── _messageid.pyi
    ├── _schema.pyi
    ├── accessors.pyi
    ├── fieldproperty.pyi
    ├── interfaces.pyi
    └── vocabulary.pyi

3 directories, 31 files

Installing the plugin directly into the virtualenv seems to work fine.

draft $ venv/bin/pip install -q mypy-zope
draft $ venv/bin/python -m mypy interface.py
Success: no issues found in 1 source file

jaraco avatar Oct 31 '20 18:10 jaraco