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

Add flag to ignore 'Skipping analyzing ...' #9789

Closed
mfarrugi opened this issue Dec 9, 2020 · 4 comments · Fixed by #14740
Closed

Add flag to ignore 'Skipping analyzing ...' #9789

mfarrugi opened this issue Dec 9, 2020 · 4 comments · Fixed by #14740
Labels
feature topic-configuration Configuration files and flags

Comments

@mfarrugi
Copy link

mfarrugi commented Dec 9, 2020

Pitch

Currently --ignore-missing-imports silences all 3 different errors listed in missing-imports, but missing-type-hints-for-third-party-library is closer to a warning than an error.

The current solution is to list the packages to ignore in a configuration file, which is particularly onerous when there are many packages being built and type-checked.

Feature

Add a flag (eg. --ignore-untyped-imports) that either ignores this error, or downgrades it to a warning:

error: Skipping analyzing X: found module but no type hints or library stubs

Alternatively:

  • the unable-to-find-module error could be changed to no longer be skipped by --ignore-missing-imports, as that is nearly always a misconfiguration of mypy
  • each case could be guarded by a separate flag.

Implementation

https://github.com/python/mypy/blob/master/mypy/build.py#L2410-L2411 and other references to options.ignore_missing_imports would need to be changed.

@hauntsaninja
Copy link
Collaborator

Reasonable request, although I'm wary of adding more knobs to mypy's import following... I think in practice people don't even understand the existing ones very well and they're a common source of confusion. I'd also phrase it as --ignore-untyped-imports.
Note that of those three errors, you won't run into one of them since typeshed is virtually complete wrt stdlib right now. In fact, I recently removed documentation of that error in #9675.
Finally, I'd personally contend with the assertion that it's closer to a warning than an error :-) All three of them have the same potential effect: causing a lot of your code to go unchecked.

@mfarrugi
Copy link
Author

mfarrugi commented Dec 9, 2020 via email

@cpoptic
Copy link

cpoptic commented Aug 17, 2022

I'd counter that this is an excellent feature request. Here's why:

Often what mypy calls "errors" of "missing stubs" involve a 3rd party external library that the user is merely importing to extend their own code.

It boils down to how much the user trusts these 3rd party libraries.

For instance, I've gotten the Skipping analyzing "numpy": module is installed, but missing library stubs error when importing the numpy and pandas libraries. Those are some of most heavily used python libraries and most users ascribe to them a reasonable amount of trust that they work. Therefore, mypy should not throw errors for those library imports.

Now I will concede that other 3rd party libraries that are not as well tested as the two above could very well cause a lot of your code to go unchecked, and therefore it would be reasonable for mypy to throw an error if those libraries are missing stubs.

So in summary, numpy and pandas should probably not throw errors if missing library stubs.
But my_random_untested_3rd_party_library probably should, at least by default.

Also I agree with @mfarrugi, as most users will probably not bother fixing "untyped-imports" from a 3rd party library that they are likely not familiar with aside from how to call functions to use within their code.
But "missing-imports" is obviously a much more serious error that they will fix.
The two errors do not have the same level of "actionable" fixes.

hauntsaninja added a commit to hauntsaninja/mypy that referenced this issue Feb 20, 2023
Resolves python#9789

Users could use `--disable-error-code=import-untyped` to only ignore
errors about libraries not having stubs, but continue to get errors
about e.g. typos in an import name.

The sub error code mechanism is new. Note that users will now get a
different error code depending on whether or not a package is installed,
and may not know that they can use the parent error code to ignore the
issue regardless. I think this is okay, in general type checking results
can change if you run them in two different environments.
hauntsaninja added a commit that referenced this issue Aug 10, 2023
Resolves #9789

Users could use `--disable-error-code=import-untyped` to only ignore
errors about libraries not having stubs, but continue to get errors
about e.g. typos in an import name.

The error subcode mechanism is new from #14570. Note that users will now
get a different error code depending on whether or not a package is
installed, and may not know that they can use the parent error code to
ignore the issue regardless. I think this is okay, in general type
checking results can change if you run them in two different
environments. Note also that with `--warn-unused-ignore` / `--strict`
mypy will complain about not having the most specific error code
@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Aug 10, 2023

On mypy master, you can use --disable-error-code=import-untyped to silence all errors for third party packages that are located but missing stubs (as opposed to the import-not-found error code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature topic-configuration Configuration files and flags
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants