Repository navigation
chore(types): narrow sync/async protocol unions with isinstance for mypy 2 - #80
Merged
Merged
Conversation
…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.
✅ Code Quality Report
Quality Gates
🎉 All quality gates passed! This PR maintains high code quality standards. 📊 View detailed MFCQI breakdownRun |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Unblocks #77 (Dependabot's mypy 1.20.2 to 2.4.1 bump), whose lint job fails with three
union-attrerrors.What changed
run_guards_sync,run_sensors_syncandMulticastStuckHandler.handle_stuckbind the sync method once (getattr(member, "<sync method>", None)) and skip the member when it is absent, instead of testinghasattrand then calling through the union. mypy 2.4 no longer narrows a union of runtime-checkable protocols onhasattr; the bound callable type-checks under both 1.20 and 2.4. A first attempt usedisinstanceagainst the sync protocol, which also demands thenamemember 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
uv run mypy langgoapwith the locked mypy 1.20.2: clean. With an overlay of mypy 2.4.1 (uv run --with mypy==2.4.1 python -m mypy langgoap): clean, where main reports the three errors from build(deps-dev): bump mypy from 1.20.2 to 2.4.1 in the python-dependencies group across 1 directory #77's lint log.After this merges, rebase #77 (
@dependabot rebase) and its lint job should pass. NoFixesline: there is no issue for this.