Welcome to Mypy documentation!
Mypy is a static type checker for Python 3 and Python 2.7.
First steps
- First steps
- Cheat sheets
- Type system reference
- Built-in types
- Type inference and type annotations
- Kinds of types
- Class basics
- Protocols and structural subtyping
- Type checking Python 2 code
- Dynamically typed code
- Casts and type assertions
- Duck type compatibility
- Stub files
- Generics
- More types
- Literal types
- Final names, methods and classes
- Metaclasses
- Configuring and running mypy
- Running mypy and managing imports
- The mypy command line
- Specifying what to type check
- Optional arguments
- Config file
- Import discovery
- Platform configuration
- Disallow dynamic typing
- Untyped definitions and calls
- None and Optional handling
- Configuring warnings
- Miscellaneous strictness flags
- Configuring error messages
- Incremental mode
- Advanced options
- Report generation
- Miscellaneous
- The mypy configuration file
- Config file format
- Per-module and global options
- Inverting option values
- Examples
- Import discovery
- Platform configuration
- Disallow dynamic typing
- Untyped definitions and calls
- None and Optional handling
- Configuring warnings
- Suppressing errors
- Miscellaneous strictness flags
- Configuring error messages
- Incremental mode
- Advanced options
- Report generation
- Miscellaneous
- Inline configuration
- Mypy daemon (mypy server)
- Using installed packages
- Extending and integrating mypy
- Automatic stub generation (stubgen)
- Miscellaneous
- Common issues and solutions
- Can’t install mypy using pip
- No errors reported for obviously wrong code
- Spurious errors and locally silencing the checker
- Ignoring a whole file
- Unexpected errors about ‘None’ and/or ‘Optional’ types
- Mypy runs are slow
- Types of empty collections
- Redefinitions with incompatible types
- Invariance vs covariance
- Declaring a supertype as variable type
- Complex type tests
- Python version and system platform checks
- Displaying the type of an expression
- Import cycles
- Using classes that are generic in stubs but not at runtime
- Silencing linters
- Covariant subtyping of mutable protocol members is rejected
- Dealing with conflicting names
- Using a development mypy build
- Variables vs type aliases
- Incompatible overrides
- Supported Python features
- Error codes
- Error codes enabled by default
- Check that attribute exists [attr-defined]
- Check that attribute exists in each union item [union-attr]
- Check that name is defined [name-defined]
- Check arguments in calls [call-arg]
- Check argument types [arg-type]
- Check calls to overloaded functions [call-overload]
- Check validity of types [valid-type]
- Require annotation if variable type is unclear [var-annotated]
- Check validity of overrides [override]
- Check that function returns a value [return]
- Check that return value is compatible [return-value]
- Check types in assignment statement [assignment]
- Check type variable values [type-var]
- Check uses of various operators [operator]
- Check indexing operations [index]
- Check list items [list-item]
- Check dict items [dict-item]
- Check TypedDict items [typeddict-item]
- Check that type of target is known [has-type]
- Check that import target can be found [import]
- Check that each name is defined once [no-redef]
- Check that called function returns a value [func-returns-value]
- Check instantiation of abstract classes [abstract]
- Check the target of NewType [valid-newtype]
- Check the return type of exit [exit-return]
- Report syntax errors [syntax]
- Miscellaneous checks [misc]
- Error codes for optional checks
- Check that type arguments exist [type-arg]
- Check that every function has an annotation [no-untyped-def]
- Check that cast is not redundant [redundant-cast]
- Check that comparisons are overlapping [comparison-overlap]
- Check that no untyped functions are called [no-untyped-call]
- Check that function does not return Any value [no-any-return]
- Check that types have no Any components due to missing imports [no-any-unimported]
- Check that statement or expression is unreachable [unreachable]
- New features in Python 3.6
- Additional features
- Frequently Asked Questions
- Why have both dynamic and static typing?
- Would my project benefit from static typing?
- Can I use mypy to type check my existing Python code?
- Will static typing make my programs run faster?
- How do I type check my Python 2 code?
- Is mypy free?
- Can I use duck typing with mypy?
- I like Python and I have no need for static typing
- How are mypy programs different from normal Python?
- How is mypy different from Cython?
- Mypy is a cool project. Can I help?
- Common issues and solutions