From f46bf762d7381f30c5cda4b61e9b85d0057eb1cd Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Wed, 30 Aug 2023 18:35:13 -0700 Subject: [PATCH 1/3] Match note error codes to import error codes Fixes #16003 --- mypy/build.py | 2 +- test-data/unit/pep561.test | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mypy/build.py b/mypy/build.py index 525d5f436e7e..39629c2dc455 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -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) diff --git a/test-data/unit/pep561.test b/test-data/unit/pep561.test index e8ebbd03dca7..9969c2894c36 100644 --- a/test-data/unit/pep561.test +++ b/test-data/unit/pep561.test @@ -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 From 79c8cfe1d3505dea76242d334bc1e57faf692907 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Wed, 30 Aug 2023 19:50:35 -0700 Subject: [PATCH 2/3] fix self check --- mypy/report.py | 2 +- mypy/test/testcheck.py | 2 +- mypy/test/testcmdline.py | 2 +- mypy/test/testreports.py | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mypy/report.py b/mypy/report.py index 5d93351aa37d..d5f16464c0fb 100644 --- a/mypy/report.py +++ b/mypy/report.py @@ -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: diff --git a/mypy/test/testcheck.py b/mypy/test/testcheck.py index 7b81deeafe9d..98328e070232 100644 --- a/mypy/test/testcheck.py +++ b/mypy/test/testcheck.py @@ -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 diff --git a/mypy/test/testcmdline.py b/mypy/test/testcmdline.py index 30ecef07a821..9bc02d319964 100644 --- a/mypy/test/testcmdline.py +++ b/mypy/test/testcmdline.py @@ -20,7 +20,7 @@ ) try: - import lxml # type: ignore[import] + import lxml # type: ignore[import-untyped] except ImportError: lxml = None diff --git a/mypy/test/testreports.py b/mypy/test/testreports.py index a422b4bb2a7b..5ff315f83ba8 100644 --- a/mypy/test/testreports.py +++ b/mypy/test/testreports.py @@ -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 @@ -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 From 9ddf6b7f50f7fa043a8b74cee39ab2967e4b1301 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Wed, 30 Aug 2023 20:13:37 -0700 Subject: [PATCH 3/3] fix test --- mypy/errors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy/errors.py b/mypy/errors.py index 680b7f1d31ea..a678b790cb8c 100644 --- a/mypy/errors.py +++ b/mypy/errors.py @@ -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: