Ruff/Mypy Workflow (tennis-lab)
Scope
Use this skill for running and fixing lint/type checks in this repo:
- •Ruff (lint + format)
- •Mypy (type checking)
- •Pre-commit (wrapper for ruff/mypy hooks)
Where settings live
- •
pyproject.toml- •
[tool.ruff],[tool.ruff.lint],[tool.ruff.format] - •
[tool.mypy]and overrides
- •
- •
.pre-commit-config.yaml(local hooks for ruff/mypy)
Recommended run order
Run from repo root, using uv to respect locked deps:
bash
uv sync uv run ruff check --fix uv run ruff format uv run mypy --follow-imports=skip
Notes:
- •Ruff uses
--fixfor auto-fixes and--exit-non-zero-on-fixin pre-commit, so re-run after it applies fixes. - •Keep
uv runfor consistency with repo tooling.
Pre-commit usage
Configured hooks:
- •Ruff:
uv run --no-sync ruff check --fix --exit-non-zero-on-fix - •Mypy:
uv run --no-sync mypy --follow-imports=skip
Run on changed files:
bash
uv run --no-sync pre-commit run --show-diff-on-failure --files <paths>
If ruff fixes files, re-run the pre-commit command until it exits 0.
Ruff policy
- •Primary fixer:
ruff check --fix. - •Formatting:
ruff format(Black-compatible style in config). - •Line length: 88; ignore
E501and star-import warnings (F403,F405). - •Keep changes minimal and aligned with enabled rules:
E,F,UP,B,SIM,I.
Mypy policy
Strict-ish defaults (e.g. disallow_untyped_defs, no_implicit_optional).
Overrides:
- •Many external libs (
cv2,torch,ultralytics, etc.) useignore_missing_imports = true. - •
third_party.*usesignore_errors = true.
Fix strategy (in order):
- •Add/propagate type hints on public functions and return types.
- •Introduce
TypedDict,Protocol, or dataclasses for structured data. - •Use
typing.castor narrow withisinstancewhen needed. - •Use
# type: ignore[<code>]only as a last resort, and justify with a short inline comment.
Common failure patterns and fixes
- •Ruff import sorting: let
ruff check --fixreorder imports. - •Ruff unused imports/variables: remove or prefix with
_if truly unused. - •Mypy missing stubs: prefer explicit types or add to
ignore_missing_importsonly if external. - •Mypy
no-untyped-def: annotate function signatures and return types. - •Mypy
arg-type/assignment: usecast,TypedDict, or refactor to correct type.