Mypy: Unable to suppress `No library stub file for module...` error

Created on 1 Sep 2017  路  8Comments  路  Source: python/mypy

Hi,

In the command line (on windows 10 using Python 3.6) I run mypy <my_module_name>. The output is very informative and has revealed a lot of missing types in my python module.

However, There is currently no mypy switch to suppress the 300+ errors of the form:

-No library stub file for module 'numpy'
-No library stub file for module 'scipy'
-No library stub file for module 'matplotlib'

What is the best way to get around this? I need a clean sheet from the mypy command if I want to integrate a mypy test ainto the build process for my module on gitlab or github.

Most helpful comment

We didn't use the hammer option of total ignoring imports, because warnings about modules that didn't exist was great for CI. So we ended up suppressing stub warnings one by one with our mypy.ini file, like the following:

mypy.ini

[mypy-tornado.*]
ignore_missing_imports = True

[mypy-pandas.*]
ignore_missing_imports = True

[mypy-numpy.*]
ignore_missing_imports = True

[mypy-sklearn.*]
ignore_missing_imports = True

[mypy-matplotlib.*]
ignore_missing_imports = True

[mypy-scipy.*]
ignore_missing_imports = True

We run mypy --config-file=../mypy.ini ./**/*.py to type check, following imports as per normal.

All 8 comments

You probably want to use 鈥搃gnore-missing-imports or one of the more relaxed options specified here: https://mypy.readthedocs.io/en/latest/command_line.html#following-imports-or-not

That will cause Mypy to not raise errors if it doesn't find stubs for the modules.

Ah, So sorry. I thought I tried that!

Yep, that switch works perfectly, thanks for the fantastic tool!

Is this the only way to suppress this warning?

The documentation for --ignore-missing imports states:

--ignore-missing-imports suppresses error messages about imports that cannot be resolved (see Following imports or not? for some examples).

This seems extremely broad, as (I believe) this also squelches errors on import foo when module foo does not exist (not just that it has no stub file). Although to be honest I'm new to mypy so I might have misinterpreted what this means. What about a flag to suppress the absence of stub files for selected modules that are known to not have stub files?

Example usage: --ignore-missing-stubs=foo,bar,baz. Or specify this explicitly in a config file.

Currently, a large number of python modules lack stub files, so having a way to surgically suppress this warning would be extremely helpful, especially in automated builds.

Yeah, an extra flag could help here. Do you want to help adding it by submitting a PR?

Let me give this a try.

We didn't use the hammer option of total ignoring imports, because warnings about modules that didn't exist was great for CI. So we ended up suppressing stub warnings one by one with our mypy.ini file, like the following:

mypy.ini

[mypy-tornado.*]
ignore_missing_imports = True

[mypy-pandas.*]
ignore_missing_imports = True

[mypy-numpy.*]
ignore_missing_imports = True

[mypy-sklearn.*]
ignore_missing_imports = True

[mypy-matplotlib.*]
ignore_missing_imports = True

[mypy-scipy.*]
ignore_missing_imports = True

We run mypy --config-file=../mypy.ini ./**/*.py to type check, following imports as per normal.

@boompig - To add to @lingz nice example... You can find more information about the current module specific settings in the per module flags section in the docs.

It would be great if there was some way of specifying a requirements file as a source for packages to ignore.

Was this page helpful?
0 / 5 - 0 ratings