KEMBAR78
documentation for module-level `# type: ignore` is unclear · Issue #7839 · python/mypy · GitHub
Skip to content

documentation for module-level # type: ignore is unclear #7839

@bwo

Description

@bwo

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions