Skip to content

Commit

Permalink
Match note error codes to import error codes (#16004)
Browse files Browse the repository at this point in the history
Fixes #16003. Follow up to #14740
  • Loading branch information
hauntsaninja authored Sep 2, 2023
1 parent 0c29507 commit 17e9e22
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2798,7 +2798,7 @@ def module_not_found(
for note in notes:
if "{stub_dist}" in note:
note = note.format(stub_dist=stub_distribution_name(module))
errors.report(line, 0, note, severity="note", only_once=True, code=codes.IMPORT)
errors.report(line, 0, note, severity="note", only_once=True, code=code)
if reason is ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED:
manager.missing_stub_packages.add(stub_distribution_name(module))
errors.set_import_context(save_import_context)
Expand Down
2 changes: 1 addition & 1 deletion mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def _add_error_info(self, file: str, info: ErrorInfo) -> None:
self.error_info_map[file].append(info)
if info.blocker:
self.has_blockers.add(file)
if info.code is IMPORT:
if info.code in (IMPORT, IMPORT_UNTYPED, IMPORT_NOT_FOUND):
self.seen_import_error = True

def _filter_error(self, file: str, info: ErrorInfo) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion mypy/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from mypy.version import __version__

try:
from lxml import etree # type: ignore[import]
from lxml import etree # type: ignore[import-untyped]

LXML_INSTALLED = True
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion mypy/test/testcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from mypy.test.update_data import update_testcase_output

try:
import lxml # type: ignore[import]
import lxml # type: ignore[import-untyped]
except ImportError:
lxml = None

Expand Down
2 changes: 1 addition & 1 deletion mypy/test/testcmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)

try:
import lxml # type: ignore[import]
import lxml # type: ignore[import-untyped]
except ImportError:
lxml = None

Expand Down
4 changes: 2 additions & 2 deletions mypy/test/testreports.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from mypy.test.helpers import Suite, assert_equal

try:
import lxml # type: ignore[import]
import lxml # type: ignore[import-untyped]
except ImportError:
lxml = None

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

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

cobertura_package = CoberturaPackage("foobar")
cobertura_package.covered_lines = 21
Expand Down
1 change: 1 addition & 0 deletions test-data/unit/pep561.test
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ a.bf(False)
b.bf(False)
a.bf(1)
b.bf(1)
import typedpkg_ns.whatever as c # type: ignore[import-untyped]
[out]
testNamespacePkgWStubs.py:4: error: Skipping analyzing "typedpkg_ns.b.bbb": module is installed, but missing library stubs or py.typed marker
testNamespacePkgWStubs.py:4: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Expand Down

0 comments on commit 17e9e22

Please sign in to comment.