Skip to content

Commit cca70fc

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 e2b9520 commit cca70fc

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
@@ -660,3 +660,24 @@ from foo.empty import *
660660
if False:
661661
a = 1
662662
a
663+
664+
[case testReturnTypeIgnoreAfterUnknownImport]
665+
-- Return type ignores after unknown imports and unused modules are respected on the second pass.
666+
$ dmypy start -- --warn-unused-ignores --no-error-summary
667+
Daemon started
668+
$ dmypy check -- foo.py
669+
foo.py:2: error: Cannot find implementation or library stub for module named "a_module_which_does_not_exist" [import-not-found]
670+
foo.py:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
671+
== Return code: 1
672+
$ dmypy check -- foo.py
673+
foo.py:2: error: Cannot find implementation or library stub for module named "a_module_which_does_not_exist" [import-not-found]
674+
foo.py:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
675+
== Return code: 1
676+
677+
[file unused/__init__.py]
678+
[file unused/empty.py]
679+
[file foo.py]
680+
from unused.empty import *
681+
import a_module_which_does_not_exist
682+
def is_foo() -> str:
683+
return True # type: ignore

0 commit comments

Comments
 (0)