From 6f67d075ee2d24f09ecfbf0776bb15aad3c07da6 Mon Sep 17 00:00:00 2001 From: Charlie Denton Date: Wed, 12 Apr 2023 16:02:45 +0100 Subject: [PATCH] Add a failing test for type ignores in dmypy This catches a regression caused by the previous attempt to fix #9655 where "type: ignore" comments are erroneously marked as unused in re-runs of dmypy. Ref: https://github.com/python/mypy/pull/14835 --- test-data/unit/daemon.test | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test-data/unit/daemon.test b/test-data/unit/daemon.test index 15d1f64b49cb8..084d2de17d539 100644 --- a/test-data/unit/daemon.test +++ b/test-data/unit/daemon.test @@ -668,3 +668,24 @@ from foo.empty import * if False: a = 1 a + +[case testReturnTypeIgnoreAfterUnknownImport] +-- Return type ignores after unknown imports and unused modules are respected on the second pass. +$ dmypy start -- --warn-unused-ignores --no-error-summary +Daemon started +$ dmypy check -- foo.py +foo.py:2: error: Cannot find implementation or library stub for module named "a_module_which_does_not_exist" [import-not-found] +foo.py:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports +== Return code: 1 +$ dmypy check -- foo.py +foo.py:2: error: Cannot find implementation or library stub for module named "a_module_which_does_not_exist" [import-not-found] +foo.py:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports +== Return code: 1 + +[file unused/__init__.py] +[file unused/empty.py] +[file foo.py] +from unused.empty import * +import a_module_which_does_not_exist +def is_foo() -> str: + return True # type: ignore