1. Setup

  1. Update your requirements-dev.txt to include line:
     mypy
    
  2. Install it using one of the following:
     $ pip install mypy
     $ pip install -r requirements-dev.txt
     $ make install-dev
    
  3. 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:

  1. Add target to Makefile. With specific directories to check as args. e.g.
     typecheck
         mypy my_project tests
    
  2. 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