Skip to content
Latchkey

mypy: Static Type Checking Command Reference

Catch type errors before runtime.

mypy statically checks Python type annotations, flagging mismatches before they reach runtime. CI runs it as a gate so type regressions fail the build.

Common flags / usage

  • mypy src/ -- type-check a package or path
  • --strict -- enable the full set of strict checks
  • --ignore-missing-imports -- skip unresolved third-party imports
  • --install-types --non-interactive -- fetch missing stub packages
  • --cache-dir DIR -- control the incremental cache location

Example

shell
- run: pip install mypy
- uses: actions/cache@v4
  with:
    path: .mypy_cache
    key: mypy-${{ hashFiles('**/*.py') }}
- run: mypy --strict src/

In CI

mypy is incremental -- cache .mypy_cache across runs for a big speedup. Missing third-party stubs cause errors; install stub packages (or run --install-types --non-interactive) rather than blanket --ignore-missing-imports, which hides real issues.

Key takeaways

  • mypy gates the build on static type-checking errors.
  • Cache .mypy_cache to make repeated CI runs much faster.
  • Install type stubs instead of broadly ignoring missing imports.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →