📝 Edit page
➕ Add page
How to add Mypy to your project
How to install and run Mypy to your project for type checking
1. Setup
- Update your requirements-dev.txt to include line:
mypy
- Install it using one of the following:
$ pip install mypy $ pip install -r requirements-dev.txt $ make install-dev
- Update
.gitignore
to include this line:.mypy_cache/
2. Validate types
Add type checks to you .py
files.
Check types directly.
$ mypy my_project tests
Or with make
:
- Add target to Makefile. With specific directories to check as args. e.g.
typecheck mypy my_project tests
- Check types.
make typecheck
Or check-types
or type-check
.
3. Add to CI/CD pipeline
Add a step your pipeline such GitHub Actions.
main.yml
steps: - name: Check types run: make check-types