Skip to content

Commit e78df55

Browse files
hauntsaninjaJukkaL
authored andcommittedOct 10, 2023
Match note error codes to import error codes (#16004)
Fixes #16003. Follow up to #14740
1 parent d376633 commit e78df55

File tree

7 files changed

+8
-7
lines changed

7 files changed

+8
-7
lines changed
 

‎mypy/build.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2798,7 +2798,7 @@ def module_not_found(
27982798
for note in notes:
27992799
if "{stub_dist}" in note:
28002800
note = note.format(stub_dist=stub_distribution_name(module))
2801-
errors.report(line, 0, note, severity="note", only_once=True, code=codes.IMPORT)
2801+
errors.report(line, 0, note, severity="note", only_once=True, code=code)
28022802
if reason is ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED:
28032803
manager.missing_stub_packages.add(stub_distribution_name(module))
28042804
errors.set_import_context(save_import_context)

‎mypy/errors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ def _add_error_info(self, file: str, info: ErrorInfo) -> None:
469469
self.error_info_map[file].append(info)
470470
if info.blocker:
471471
self.has_blockers.add(file)
472-
if info.code is IMPORT:
472+
if info.code in (IMPORT, IMPORT_UNTYPED, IMPORT_NOT_FOUND):
473473
self.seen_import_error = True
474474

475475
def _filter_error(self, file: str, info: ErrorInfo) -> bool:

‎mypy/report.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from mypy.version import __version__
2626

2727
try:
28-
from lxml import etree # type: ignore[import]
28+
from lxml import etree # type: ignore[import-untyped]
2929

3030
LXML_INSTALLED = True
3131
except ImportError:

‎mypy/test/testcheck.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from mypy.test.update_data import update_testcase_output
2727

2828
try:
29-
import lxml # type: ignore[import]
29+
import lxml # type: ignore[import-untyped]
3030
except ImportError:
3131
lxml = None
3232

‎mypy/test/testcmdline.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
)
2121

2222
try:
23-
import lxml # type: ignore[import]
23+
import lxml # type: ignore[import-untyped]
2424
except ImportError:
2525
lxml = None
2626

‎mypy/test/testreports.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from mypy.test.helpers import Suite, assert_equal
88

99
try:
10-
import lxml # type: ignore[import]
10+
import lxml # type: ignore[import-untyped]
1111
except ImportError:
1212
lxml = None
1313

@@ -22,7 +22,7 @@ def test_get_line_rate(self) -> None:
2222

2323
@pytest.mark.skipif(lxml is None, reason="Cannot import lxml. Is it installed?")
2424
def test_as_xml(self) -> None:
25-
import lxml.etree as etree # type: ignore[import]
25+
import lxml.etree as etree # type: ignore[import-untyped]
2626

2727
cobertura_package = CoberturaPackage("foobar")
2828
cobertura_package.covered_lines = 21

‎test-data/unit/pep561.test

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ a.bf(False)
167167
b.bf(False)
168168
a.bf(1)
169169
b.bf(1)
170+
import typedpkg_ns.whatever as c # type: ignore[import-untyped]
170171
[out]
171172
testNamespacePkgWStubs.py:4: error: Skipping analyzing "typedpkg_ns.b.bbb": module is installed, but missing library stubs or py.typed marker
172173
testNamespacePkgWStubs.py:4: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

0 commit comments

Comments
 (0)
Please sign in to comment.