Check that types have no Any components due to missing imports [no-any-unimported]
If you use —disallow-any-unimported
, mypy generates an error if a component ofa type becomes Any
because mypy couldn’t resolve an import. These “stealth”Any
types can be surprising and accidentally cause imprecise type checking.
In this example, we assume that mypy can’t find the module animals
, which meansthat Cat
falls back to Any
in a type annotation:
- # mypy: disallow-any-unimported
- from animals import Cat # type: ignore
- # Error: Argument 1 to "feed" becomes "Any" due to an unfollowed import [no-any-unimported]
- def feed(cat: Cat) -> None:
- ...