chore(types): mypy strict for 5 modules (batch 1 of #34)#42
Merged
Conversation
…ry, tools.context, tools.registry (#34) First batch of the mypy ignore_errors → per-line migration. Five modules (1066 LOC total) lifted from the blanket ignore_errors override and back into strict checking: - locus.core.reducers (445 LOC) - locus.core.send (322 LOC) - locus.models.registry (150 LOC) - locus.tools.context (67 LOC) - locus.tools.registry (82 LOC) Real fixes (not type-ignore covers): - core/reducers.py — AddMessages.__call__ now narrows the str sentinel branch up front, accepts list[Message] | Message | str, and raises on unrecognized strings (replaces the buggy [update] wrap that was producing list[str] for non-list inputs). - core/protocols.py — ModelProtocol.stream() declared as def (not async def) so the Protocol matches concrete async-generator implementations. async def with yield returns AsyncIterator[X] directly, not Coroutine[..., AsyncIterator[X]]; the Protocol now types correctly. - models/base.py — same change to the duplicate ModelProtocol there. - tools/registry.py — __iter__ return type annotated as Iterator[Tool] (was missing); collections.abc.Iterator import added. - tools/context.py — confidence property cast to float at the boundary so the Any-typed self.state doesn't poison the return. Targeted # type: ignore[code] annotations with justification: - core/reducers.py — MaxValue/MinValue use unbounded T; mypy can't prove SupportsRichComparison on max()/min() so two type:ignore[call-overload,no-any-return] lines. - core/reducers.py — get_args(annotation)[1] returns Any from typing.get_args so the callable-narrowed return needs type:ignore[no-any-return]. - core/send.py — is_send_list() is a custom TypeGuard-style check whose narrowing mypy can't propagate; one type:ignore[no-any-return]. - tools/registry.py — __iter__ override Liskov mismatch with Pydantic's BaseModel.__iter__ is intentional and predates strict typing; type:ignore[override] with justification. - models/registry.py — three lambdas + the _make_oci function cast concrete Pydantic model classes to ModelProtocol at the registration boundary because mypy's Callable-variance check doesn't propagate structural-Protocol narrowing. All 3,246 unit tests pass; pre-commit clean (ruff lint, ruff format, mypy, codespell, markdownlint, gitleaks); mkdocs --strict clean. EOF Signed-off-by: Federico Kamelhar <federico.kamelhar@oracle.com>
This was referenced May 2, 2026
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.
First batch of issue #34 — migrate mypy `ignore_errors` blanket to per-line.
Lifted modules (1066 LOC, all in strict mode now)
Real fixes (not type-ignore covers)
Targeted `# type: ignore[code]` annotations (with justification comments)
Test plan
What remains for issue #34
12 more module groups still under `ignore_errors`. Will land in subsequent batches:
```
locus.rag.* locus.memory.* locus.integrations.*
locus.streaming.* locus.loop.* locus.playbooks.*
locus.server.* locus.multiagent.graph locus.hooks.builtin.*
locus.reasoning.* locus.skills.* locus.a2a.*
```