Type ignore comments erroneously marked as unused by dmypy (#15043) · python/mypy@a4801f9
@@ -648,6 +648,143 @@ from demo.test import a
648648[file demo/test.py]
649649a: int
650650651+[case testUnusedTypeIgnorePreservedOnRerun]
652+-- Regression test for https://github.com/python/mypy/issues/9655
653+$ dmypy start -- --warn-unused-ignores --no-error-summary --hide-error-codes
654+Daemon started
655+$ dmypy check -- bar.py
656+bar.py:2: error: Unused "type: ignore" comment
657+== Return code: 1
658+$ dmypy check -- bar.py
659+bar.py:2: error: Unused "type: ignore" comment
660+== Return code: 1
661+662+[file foo/__init__.py]
663+[file foo/empty.py]
664+[file bar.py]
665+from foo.empty import *
666+a = 1 # type: ignore
667+668+[case testTypeIgnoreWithoutCodePreservedOnRerun]
669+-- Regression test for https://github.com/python/mypy/issues/9655
670+$ dmypy start -- --enable-error-code ignore-without-code --no-error-summary
671+Daemon started
672+$ dmypy check -- bar.py
673+bar.py:2: error: "type: ignore" comment without error code [ignore-without-code]
674+== Return code: 1
675+$ dmypy check -- bar.py
676+bar.py:2: error: "type: ignore" comment without error code [ignore-without-code]
677+== Return code: 1
678+679+[file foo/__init__.py]
680+[file foo/empty.py]
681+[file bar.py]
682+from foo.empty import *
683+a = 1 # type: ignore
684+685+[case testPossiblyUndefinedVarsPreservedAfterRerun]
686+-- Regression test for https://github.com/python/mypy/issues/9655
687+$ dmypy start -- --enable-error-code possibly-undefined --no-error-summary
688+Daemon started
689+$ dmypy check -- bar.py
690+bar.py:4: error: Name "a" may be undefined [possibly-undefined]
691+== Return code: 1
692+$ dmypy check -- bar.py
693+bar.py:4: error: Name "a" may be undefined [possibly-undefined]
694+== Return code: 1
695+696+[file foo/__init__.py]
697+[file foo/empty.py]
698+[file bar.py]
699+from foo.empty import *
700+if False:
701+ a = 1
702+a
703+704+[case testUnusedTypeIgnorePreservedOnRerunWithIgnoredMissingImports]
705+$ dmypy start -- --no-error-summary --ignore-missing-imports --warn-unused-ignores
706+Daemon started
707+$ dmypy check foo
708+foo/main.py:3: error: Unused "type: ignore" comment [unused-ignore]
709+== Return code: 1
710+$ dmypy check foo
711+foo/main.py:3: error: Unused "type: ignore" comment [unused-ignore]
712+== Return code: 1
713+714+[file unused/__init__.py]
715+[file unused/submodule.py]
716+[file foo/empty.py]
717+[file foo/__init__.py]
718+from foo.main import *
719+from unused.submodule import *
720+[file foo/main.py]
721+from foo import empty
722+from foo.does_not_exist import *
723+a = 1 # type: ignore
724+725+[case testModuleDoesNotExistPreservedOnRerun]
726+$ dmypy start -- --no-error-summary --ignore-missing-imports
727+Daemon started
728+$ dmypy check foo
729+foo/main.py:1: error: Module "foo" has no attribute "does_not_exist" [attr-defined]
730+== Return code: 1
731+$ dmypy check foo
732+foo/main.py:1: error: Module "foo" has no attribute "does_not_exist" [attr-defined]
733+== Return code: 1
734+735+[file unused/__init__.py]
736+[file unused/submodule.py]
737+[file foo/__init__.py]
738+from foo.main import *
739+[file foo/main.py]
740+from foo import does_not_exist
741+from unused.submodule import *
742+743+[case testReturnTypeIgnoreAfterUnknownImport]
744+-- Return type ignores after unknown imports and unused modules are respected on the second pass.
745+$ dmypy start -- --warn-unused-ignores --no-error-summary
746+Daemon started
747+$ dmypy check -- foo.py
748+foo.py:2: error: Cannot find implementation or library stub for module named "a_module_which_does_not_exist" [import-not-found]
749+foo.py:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
750+== Return code: 1
751+$ dmypy check -- foo.py
752+foo.py:2: error: Cannot find implementation or library stub for module named "a_module_which_does_not_exist" [import-not-found]
753+foo.py:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
754+== Return code: 1
755+756+[file unused/__init__.py]
757+[file unused/empty.py]
758+[file foo.py]
759+from unused.empty import *
760+import a_module_which_does_not_exist
761+def is_foo() -> str:
762+ return True # type: ignore
763+764+[case testAttrsTypeIgnoreAfterUnknownImport]
765+$ dmypy start -- --warn-unused-ignores --no-error-summary
766+Daemon started
767+$ dmypy check -- foo.py
768+foo.py:3: error: Cannot find implementation or library stub for module named "a_module_which_does_not_exist" [import-not-found]
769+foo.py:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
770+== Return code: 1
771+$ dmypy check -- foo.py
772+foo.py:3: error: Cannot find implementation or library stub for module named "a_module_which_does_not_exist" [import-not-found]
773+foo.py:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
774+== Return code: 1
775+776+[file unused/__init__.py]
777+[file unused/empty.py]
778+[file foo.py]
779+import attr
780+from unused.empty import *
781+import a_module_which_does_not_exist
782+783+@attr.frozen
784+class A:
785+ def __init__(self) -> None:
786+ self.__attrs_init__() # type: ignore[attr-defined]
787+651788[case testDaemonImportAncestors]
652789$ dmypy run test.py
653790Daemon started