


Mypy can make use of PEP 484 stub files when you want to use type hints for a module’s public interfaces. And you can always use inline comments like # type: ignore to keep individual lines from being flagged. On the other hand, if you’re working with a legacy codebase that doesn’t have many type definitions, you can use more relaxed options such as preventing only untyped function definitions with -disallow-untyped-defs while allowing other untyped code.

If you’re starting from scratch with a codebase and you want a preemptively aggressive linting strategy, you can use the -strict option to prevent any untyped code. This can be done with varying degrees of strictness depending on one’s needs. You can use Mypy to manually flag unannotated code, though. This way, if you're annotating a code base gradually, Myp doesn't waste its time or yours on code you are not actually trying to type-check. If your code doesn’t include type annotations, Mypy will not perform the vast majority of its code checks. When run, Mypy generates reports about your code’s consistency based on the type information it provides. Many editors and IDEs integrate Mypy Visual Studio Code’s Python extension can work with it directly. Mypy can run standalone, or from the command line, or it can work as part of an editor or IDE’s linter integration. It is essentially the prototype for how third-party type checking libraries work in Python, even if many others have come along since and expanded on its features. Work on it began in 2012, and it’s still under active development. Mypy, originally developed at Dropbox to optimize its own internal codebase, was arguably the first static type checking system for Python.
