Run mypy static type checking for Python code.
jobs:
mypy:
uses: whisller/forge-ci/.github/workflows/forge-ci-python-tools-mypy.yml@v1
with:
dependencies-cache-key: ${{ needs.dependencies.outputs.dependencies-cache-key }}| Input | Type | Required | Default | Description |
|---|---|---|---|---|
python-version |
string | No | '3.12' |
Python version to use |
working-directory |
string | No | '.' |
Working directory for type checking |
dependencies-cache-key |
string | No | '' |
Cache key from dependency-manager job |
mypy-config |
string | No | '' |
Path to custom mypy config file |
runs-on |
string | No | 'ubuntu-latest' |
Runner to use |
None
- Restore Cache: Restores dependencies if cache key provided
- Add to PATH: Adds
.venv/binto PATH for mypy access - Run mypy: Executes type checking with optional custom config
jobs:
dependencies:
uses: whisller/forge-ci/.github/workflows/forge-ci-python-tools-dependency-manager.yml@v1
mypy:
needs: dependencies
uses: whisller/forge-ci/.github/workflows/forge-ci-python-tools-mypy.yml@v1
with:
dependencies-cache-key: ${{ needs.dependencies.outputs.dependencies-cache-key }}jobs:
mypy:
uses: whisller/forge-ci/.github/workflows/forge-ci-python-tools-mypy.yml@v1
with:
mypy-config: 'config/mypy.ini'jobs:
mypy:
uses: whisller/forge-ci/.github/workflows/forge-ci-python-tools-mypy.yml@v1mypy configuration in pyproject.toml:
[tool.mypy]
python_version = "3.12"
warn_return_any = true
warn_unused_configs = true
disallow_untyped_defs = true
[[tool.mypy.overrides]]
module = "tests.*"
disallow_untyped_defs = falseOr separate mypy.ini:
[mypy]
python_version = 3.12
warn_return_any = True
warn_unused_configs = True
disallow_untyped_defs = True
[mypy-tests.*]
disallow_untyped_defs = FalseOr .mypy.ini in project root:
[mypy]
files = src/
exclude = tests/
strict = TrueProblem: mypy: command not found
Cause: mypy not installed in dependencies.
Solution: Add mypy to dev dependencies:
# Poetry
poetry add --group dev mypy
# uv
uv add --dev mypy
# venv
echo "mypy>=1.0.0" >> requirements-dev.txtProblem: "Cannot find implementation or library stub for module"
Cause: Missing type stubs for third-party libraries.
Solution: Install type stubs:
# Poetry
poetry add --group dev types-requests types-pyyaml
# uv
uv add --dev types-requests types-pyyaml
# venv
pip install types-requests types-pyyamlProblem: Too many type errors in existing codebase.
Cause: Strict type checking enabled for legacy code.
Solution: Gradual type checking adoption:
[tool.mypy]
# Start lenient
warn_return_any = false
disallow_untyped_defs = false
# Gradually enable stricter checks
warn_unused_ignores = true
warn_redundant_casts = true