Skip to content

ignore stubs but get an error if module is missing #9115

Closed
@K0ertis

Description

@K0ertis

Hi I am using mypy:0.782 with python3.5 and I want to use it to check if my imports are valid

for example I would like to raise an error for
import PIL # package pillow if its not installed on the build machine.

but mypy complains when installed:

file.py:10: error: Skipping analyzing 'PIL': found module but no type hints or library stubs
file.py:10: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)

when not installed:

file.py.py:10: error: Cannot find implementation or library stub for module named 'PIL'
file.py:10: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)

when adding #type: ignore all errors are ignored for this package, but I would like to surpress only the missing library stubs but
raise an error if the module is not found at all. I can't find a flag for that purpose.

mypy config:

[mypy]
python_version = 3.5
allow_untyped_globals=True
allow_redefinition  = True
warn_unused_configs = True
disallow_untyped_calls = False
disallow_untyped_defs = False
disallow_incomplete_defs = False
check_untyped_defs = False
disallow_untyped_decorators = False
warn_incomplete_stub  = False
warn_unused_ignores = True
ignore_errors = False
follow_imports = normal

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions