Welcome to Mypy documentation!¶
Mypy is a static type checker for Python.
- Introduction
- Basics
- Getting started
- Built-in types
- Type checking Python 2 code
- Type inference and type annotations
- Kinds of types
- User-defined types
- The Any type
- Tuple types
- Callable types (and lambdas)
- Extended Callable types
- Union types
- Optional types and the None type
- Disabling strict optional checking
- The NoReturn type
- Class name forward references
- Type aliases
- NewTypes
- Named tuples
- The type of class objects
- Text and AnyStr
- Generators
- Typing async/await
- TypedDict
- Class basics
- Instance and class attributes
- Overriding statically typed methods
- Abstract base classes and multiple inheritance
- Protocols and structural subtyping
- Predefined protocols
- Simple user-defined protocols
- Defining subprotocols and subclassing protocols
- Recursive protocols
- Using
isinstance()
with protocols
- Dynamically typed code
- Function Overloading
- Casts
- Duck type compatibility
- Common issues
- Can’t install mypy using pip
- No errors reported for obviously wrong code
- Spurious errors and locally silencing the checker
- Unexpected errors about ‘None’ and/or ‘Optional’ types
- Types of empty collections
- Redefinitions with incompatible types
- Invariance vs covariance
- Covariant subtyping of mutable protocol members is rejected
- Declaring a supertype as variable type
- Complex type tests
- Python version and system platform checks
- Displaying the type of an expression
- Import cycles
- Silencing linters
- Generics
- Supported Python features and modules
- Additional features
- The mypy command line
- The mypy configuration file
- Mypy daemon (mypy server)
- New features in Python 3.6
- Using Installed Packages
- 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 structural subtyping?
- 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?
- How is mypy different from Nuitka?
- How is mypy different from RPython or Shed Skin?
- Mypy is a cool project. Can I help?
- Mypy syntax cheat sheet (Python 2)
- Mypy syntax cheat sheet (Python 3)
- Revision history