Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
K0ertis opened this issue Jul 9, 2020 · 2 comments
Closed

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

K0ertis opened this issue Jul 9, 2020 · 2 comments
Labels

Comments

@K0ertis
Copy link

K0ertis commented Jul 9, 2020

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
@Akuli
Copy link
Contributor

Akuli commented Aug 18, 2020

Error codes are meant for things like this except that the error code is [import] in both cases

Maybe one of the error codes should be module-not-found and the other should be stubs-not-found, or something like that? then you could do # type: ignore[stubs-not-found]

@hauntsaninja
Copy link
Collaborator

I fixed this in #14740, use --disable-error-code=import-untyped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants