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:

  1. # mypy: disallow-any-unimported
  2.  
  3. from animals import Cat # type: ignore
  4.  
  5. # Error: Argument 1 to "feed" becomes "Any" due to an unfollowed import [no-any-unimported]
  6. def feed(cat: Cat) -> None:
  7. ...