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.
That will cause Mypy to not raise errors if it doesn't find stubs for the modules.
Reacted by Vincenzo Ferrari, Andrew Martin, Pranay Aryal, Martin Thoma, Lukas N.P. Egger, Vishes, Viacheslav Artemchuk, Samuel Carlsson, George J. J. Wu, Jizong's Fox and 21 more
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.
Reacted by laike9m, Hiroaki Ogasawara, Josiah, Shun Kakinoki, Jirka Daněk, Tyler Couto, Antonino Ingargiola, Max Kühn, James Ostrander, Manuel Vonthron and 16 more
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:
We run mypy --config-file=../mypy.ini ./**/*.py to type check, following imports as per normal.
Reacted by Mateusz Legięcki, laike9m, Daniel Vianna, Vishes, Samuel Carlsson, Viacheslav Artemchuk, Aru Sahni, rodrigodc, Vladimir Jimenez, Jirka Daněk and 27 more
Reacted by Jorge Leitao, Joe Osborn, Jirka Daněk, mishudark, Shuvo Saha, Konstantin Manna, gmanka and Mateusz Głowiński
@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.
Activity
emmatyping commented on Sep 1, 2017
You probably want to use –ignore-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.
henryJack commented on Sep 1, 2017
Ah, So sorry. I thought I tried that!
Yep, that switch works perfectly, thanks for the fantastic tool!
boompig commented on Jan 16, 2018
Is this the only way to suppress this warning?
The documentation for --ignore-missing imports states:
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.
gvanrossum commented on Jan 16, 2018
Yeah, an extra flag could help here. Do you want to help adding it by submitting a PR?
boompig commented on Jan 18, 2018
Let me give this a try.
Added --ignore-missing-stubs flag
Added --ignore-missing-stubs flag
lingz commented on Sep 13, 2018
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
We run mypy --config-file=../mypy.ini ./**/*.py to type check, following imports as per normal.
henryJack commented on Sep 14, 2018
@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.
mypy: fix "No library stub file for module XXXXXX"
stuaxo commented on Feb 3, 2020
It would be great if there was some way of specifying a requirements file as a source for packages to ignore.
thejaminator commented on Jan 3, 2023
It seems sad that #4491 got closed.
It can be very annoying to have to whitelist so many dependencies in your codebase.
Another way is to simply override the setting for your own codebase.
That way, your own codebase's imports gets typechecked.
i.e.