black_ruff_mypy
SKILL.md
black_ruff_mypy
Tres herramientas complementarias que se ejecutan juntas en cada commit y en CI para mantener la calidad del código Python sin debate entre developers.
When to use
Configurar en pre-commit hooks desde el primer commit. Ejecutar también en CI como gate obligatorio antes de merge.
Instructions
-
Instalar:
pip install black ruff mypy -
Configurar en
pyproject.toml:[tool.black] line-length = 100 target-version = ["py311"] [tool.ruff] line-length = 100 select = ["E", "F", "I", "N", "W", "UP", "S", "B"] ignore = ["S101"] # allow assert in tests [tool.mypy] python_version = "3.11" strict = true ignore_missing_imports = true plugins = ["pydantic.mypy"] -
Añadir a
.pre-commit-config.yaml:repos: - repo: https://github.com/psf/black rev: 23.12.0 hooks: [{id: black}] - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.1.9 hooks: [{id: ruff, args: [--fix]}] - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.8.0 hooks: [{id: mypy, additional_dependencies: [pydantic, types-redis]}] -
Instalar hooks:
pre-commit install. -
En CI:
ruff check . && black --check . && mypy backend/.
Notes
- Black reformatea automáticamente — los developers aceptan el formato sin discutir estilo.
- Ruff en modo
--fixcorrige automáticamente los errores que puede (imports desordenados, unused imports). - mypy
strict=truerequiere type annotations en todo el código — es estricto pero previene bugs sutiles en async code. - Ruff reemplaza Flake8, isort, pydocstyle y más — es 100x más rápido que las alternativas.