You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
type: ignore[import-untyped] leaves a hard-to-suppress note #16003
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:
importsentencepiece
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:
importsentencepiece# 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)
Activity
JelleZijlstra commentedon Aug 30, 2023
I suspect we set the wrong error code when emitting the note. This should be an easy fix.
Match note error codes to import error codes
hauntsaninja commentedon Aug 31, 2023
Thanks for the report and for testing with a prerelease. #16004 should fix, I'll try and get it into 1.6
Match note error codes to import error codes (#16004)
Match note error codes to import error codes (#16004)