Skip to content

Commit 0b84c46

Browse files
committed
Add a failing test for type ignores in dmypy
This catches a regression caused by the previous commits where "type: ignore" comments are erroneously marked as unused in re-runs of dmypy. As far as I can tell, this only happens in modules which contain an import that we don't know how to type (such as a module which does not exist), and a submodule which is unused.
1 parent ae4b20d commit 0b84c46

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test-data/unit/daemon.test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,3 +611,24 @@ from foo.empty import *
611611
if False:
612612
a = 1
613613
a
614+
615+
[case testReturnTypeIgnoreAfterUnknownImport]
616+
-- Return type ignores after unknown imports and unused modules are respected on the second pass.
617+
$ dmypy start -- --warn-unused-ignores --no-error-summary
618+
Daemon started
619+
$ dmypy check -- foo.py
620+
foo.py:2: error: Cannot find implementation or library stub for module named "a_module_which_does_not_exist" [import]
621+
foo.py:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
622+
== Return code: 1
623+
$ dmypy check -- foo.py
624+
foo.py:2: error: Cannot find implementation or library stub for module named "a_module_which_does_not_exist" [import]
625+
foo.py:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
626+
== Return code: 1
627+
628+
[file unused/__init__.py]
629+
[file unused/empty.py]
630+
[file foo.py]
631+
from unused.empty import *
632+
import a_module_which_does_not_exist
633+
def is_foo() -> str:
634+
return True # type: ignore

0 commit comments

Comments
 (0)