mypy
A static type checker for Python that reads type hints and reports code whose types do not fit together, without running it.
In more detail
mypy file.py checks a file; errors come with line numbers, such as passing a str where an int is expected or forgetting that a function can return None. It is installed with pip and run before tests or in continuous integration.
Example
python -m pip install mypy
mypy wordcount.pyRelated terms
- type hint — A note in a function heading or variable declaration saying what type a value should be, such as def total(prices: list[float]) -> float:.
- static type checking — Checking that values are used consistently with their declared types by analysing code without running it.
- linter — A tool that reads code or configuration without running it and flags likely mistakes and style problems.
Taught in
- Type Hints — Hands-on Python: Complete Video Course & Book