Skip to content

chore(types): narrow sync/async protocol unions with isinstance for mypy 2 - #80

Merged
bsbodden merged 2 commits into
mainfrom
chore/mypy2-protocol-narrowing
Nov 15, 2026
Merged

bsbodden merged 2 commits into
mainfrom
chore/mypy2-protocol-narrowing

Conversation

@bsbodden

@bsbodden bsbodden commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Unblocks #77 (Dependabot's mypy 1.20.2 to 2.4.1 bump), whose lint job fails with three union-attr errors.

What changed

  • run_guards_sync, run_sensors_sync and MulticastStuckHandler.handle_stuck bind the sync method once (getattr(member, "<sync method>", None)) and skip the member when it is absent, instead of testing hasattr and then calling through the union. mypy 2.4 no longer narrows a union of runtime-checkable protocols on hasattr; the bound callable type-checks under both 1.20 and 2.4. A first attempt used isinstance against the sync protocol, which also demands the name member and silently skipped duck-typed members that implement only the method; the full suite caught it and the binding approach keeps the previous acceptance.

Verification

After this merges, rebase #77 (@dependabot rebase) and its lint job should pass. No Fixes line: there is no issue for this.

…ypy 2

The sync paths of run_guards_sync, run_sensors_sync and
MulticastStuckHandler.handle_stuck skipped async-only members with
``hasattr(x, "<sync method>")``. mypy 2.4 no longer narrows a union of
runtime-checkable protocols on hasattr, so Dependabot's mypy 1.20 -> 2.4
bump (#77) failed lint with three union-attr errors. ``isinstance``
against the sync protocol narrows under both mypy 1.20 and 2.4 and
expresses the same check: the member implements the sync protocol.
…members still run

isinstance against the full runtime-checkable protocol also demands the
``name`` member, so a duck-typed stuck handler, guard or sensor that
implements only the sync method was skipped as async-only; the full
suite caught it (tests/test_graph_runtime_hygiene.py). Binding the method
with getattr keeps the previous acceptance and still narrows the union
under mypy 1.20 and 2.4.
@github-actions

Copy link
Copy Markdown

✅ Code Quality Report

Metric Score Status
MFCQI Score 0.8117704609882482 ✅ Good
Test Coverage 94% ✅ Good
Security Issues 0 ✅ Clean

Quality Gates

  • MFCQI Score: ✅ Minimum 0.75 (Current: 0.8117704609882482)
  • Test Coverage: ✅ Minimum 80% (Current: 94%)
  • Security: ✅ Zero vulnerabilities (Current: 0)

🎉 All quality gates passed! This PR maintains high code quality standards.

📊 View detailed MFCQI breakdown

Run uv run python -m mfcqi analyze langgoap locally to see detailed metrics breakdown.

@bsbodden
bsbodden merged commit 1ce10b9 into main Nov 15, 2026
19 checks passed
@bsbodden bsbodden added the maintenance CI/build/tooling maintenance label Nov 15, 2026
@bsbodden
bsbodden deleted the chore/mypy2-protocol-narrowing branch November 15, 2026 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance CI/build/tooling maintenance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant