-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrongpriority-0-hightopic-type-ignore# type: ignore comments# type: ignore commentstopic-usability
Description
My expectation of a module-level # type: ignore comment is that it will skip typechecking of everything in the module; i.e., everything would be given the type Any.
The description in the documentation such a comment "has the effect of ignoring the entire module.", is, I think, consistent with that impression, since what "ignoring" means earlier in the documentation has been basically skipping typechecking.
What it actually does, though, seems to be to cause mypy to quite literally ignore the module: it is just skipped entirely, with the result that you can't import names defined in that module in another one:
(.venv3) BenW ~ 02:10:35 $ cat foo/a.py
# type: ignore
class A(object):
pass
cat(.venv3) BenW ~ 02:10:45 $ cat foo/b.py
from foo.a import A
def b(a):
# type: (A) -> int
return len(str(type(a)))
print(b(A()))
(.venv3) BenW ~ 02:10:47 $ mypy foo
foo/b.py:1: error: Module 'foo.a' has no attribute 'A'
Found 1 error in 1 file (checked 3 source files)
This makes the feature somewhat less useful IMO, but also, I think it could be clearer in the docs that that's what it does.
nsgoetz
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongpriority-0-hightopic-type-ignore# type: ignore comments# type: ignore commentstopic-usability