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

type: ignore[import-untyped] leaves a hard-to-suppress note #16003

Closed
cebtenzzre opened this issue Aug 30, 2023 · 2 comments · Fixed by #16004
Closed

type: ignore[import-untyped] leaves a hard-to-suppress note #16003

cebtenzzre opened this issue Aug 30, 2023 · 2 comments · Fixed by #16004
Labels
bug mypy got something wrong topic-error-reporting How we report errors

Comments

@cebtenzzre
Copy link

Bug Report

type: ignore[import-untyped] leaves a note that must be silenced with type: ignore[import], but only for one of the locations.

To Reproduce

Consider two files, a.py and b.py, both with this content:

import sentencepiece

Since sentencepiece is a third-party package without type information, mypy complains:

$ mypy *.py
b.py:1: error: Skipping analyzing "sentencepiece": module is installed, but missing library stubs or py.typed marker  [import-untyped]
a.py:1: error: Skipping analyzing "sentencepiece": module is installed, but missing library stubs or py.typed marker  [import-untyped]
a.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 2 errors in 2 files (checked 2 source files)

So, let's try to shut up mypy, since our project can't do anything to fix that issue internally. First, I tried using disabled_error_codes in mypy.ini, and was met with issue #16002. Then, I tried adding type: ignore comments, like this:

import sentencepiece  # type: ignore[import-untyped]

This doesn't really work:

$ mypy *.py
a.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
a.py:1: note: Error code "import" not covered by "type: ignore" comment
Success: no issues found in 2 source files

For one file only, mypy leaves a note providing a link to the documentation, with no associated error message.

This can be worked around by using type: ignore[import] on the line it complains about, but I don't know if that has to be done for just one of the files or all of them, and how mypy decides which one. I also don't want to hide other kinds of import errors, such as a package being missing entirely, or stubs that are available but not installed.

Your Environment

  • Mypy version used: mypy 1.7.0+dev.9a0aca14724eeef580eefcd3b340678313a1930a (compiled: no)
  • Python version used: Python 3.11.3
  • Operating system and version: Arch Linux
@cebtenzzre cebtenzzre added the bug mypy got something wrong label Aug 30, 2023
@JelleZijlstra
Copy link
Member

I suspect we set the wrong error code when emitting the note. This should be an easy fix.

@hauntsaninja
Copy link
Collaborator

Thanks for the report and for testing with a prerelease. #16004 should fix, I'll try and get it into 1.6

hauntsaninja added a commit that referenced this issue Sep 2, 2023
JukkaL pushed a commit that referenced this issue Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-error-reporting How we report errors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants