Skip to content

Type hints for Board + Move; mypy CI workflow (advisory) (#46)#54

Open
dbqpdb wants to merge 2 commits into
masterfrom
feature/type-hints-board-move
Open

Type hints for Board + Move; mypy CI workflow (advisory) (#46)#54
dbqpdb wants to merge 2 commits into
masterfrom
feature/type-hints-board-move

Conversation

@dbqpdb

@dbqpdb dbqpdb commented May 14, 2026

Copy link
Copy Markdown
Owner

Summary

First pass of #46, plus its CI complement. Two commits:

  1. cfd079f — type hints on Board and Move. Annotates every method in the two most-depended-on classes per Cleanup: add complete type hints across the codebase #46's suggested order. Adds three module-level aliases (SquareName, BoardIdxs, PieceChar) for the recurring fuzzy types, and turns on from __future__ import annotations so forward references and modern union syntax just work.
  2. 518616d — mypy CI workflow. Third CI workflow file (typecheck.yml), mirrors the lint workflow pattern: runs on every push and PR, advisory (continue-on-error: true), uses --ignore-missing-imports so numpy/pandas stubs aren't needed.

Annotations only — no behavior changes

All four TestRLM cases pass; test_entered_move_processing runs to completion with the same result as before.

Mypy report (current state)

Locally: 60 errors reported by mypy rlm.py --ignore-missing-imports. The advisory workflow surfaces these in CI without blocking merge. Several map cleanly to existing bugs that are tracked separately:

The bulk of the remaining errors fall into two buckets:

  • move_elem_dict in parse_move_without_game is inferred as dict[str, str] from initialization, but gets bool and None values assigned later. Fix is a single : dict[str, Any] annotation; intentionally not bundled into this PR to keep it pure-annotation-only.
  • square_name_to_array_idxs returns tuple[int | None, int | None], which is accurate (it returns None for invalid inputs), but most call sites assume non-None. This pattern would benefit from a refactor — either raise on invalid input, or have callers handle None explicitly.

What's still out of scope

Closes #46 partially; will leave the issue open until the rest of the codebase is annotated.

🤖 Generated with Claude Code

dbqpdb and others added 2 commits May 14, 2026 19:15
First pass of #46, scoped to the two most-depended-on classes per the
issue's suggested order. Adds:

- `from __future__ import annotations` so annotations are lazy and
  Move/Board forward references work without string-quoting them.
- Module-level type aliases: SquareName (for the flexible inputs that
  square_name_to_array_idxs accepts), BoardIdxs (file_idx, rank_idx
  tuple), PieceChar (single piece letter).
- Parameter and return annotations on every method of Board and Move.

Annotations only — no behavior changes. All four TestRLM cases pass
plus test_entered_move_processing.

Follow-up passes will cover Piece + subclasses and Game/GameController.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Third CI workflow file, mirroring the lint workflow's pattern:
- Triggers on every push and every pull_request.
- continue-on-error: true so findings surface without blocking merge.
- --ignore-missing-imports keeps the workflow runnable without
  installing numpy/pandas type stubs.

Runs on rlm.py only for now; can widen once tests/ has type hints too.
Current mypy reports ~60 errors against the partially-typed codebase —
several map to bugs already filed separately (e.g. the setdefault
issue in #33, the tuple-assert in #32, and __eq__'s object signature
vs. body that assumes Move). The advisory mode means these accumulate
as a backlog rather than blocking merge.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cleanup: add complete type hints across the codebase

1 participant