Skip to content

chore(types): mypy strict for locus.loop.* + locus.reasoning.* (#34 batch 4)#46

Merged
fede-kamel merged 1 commit into
mainfrom
feat/mypy-migrate-batch4
May 2, 2026
Merged

chore(types): mypy strict for locus.loop.* + locus.reasoning.* (#34 batch 4)#46
fede-kamel merged 1 commit into
mainfrom
feat/mypy-migrate-batch4

Conversation

@fede-kamel
Copy link
Copy Markdown
Contributor

Summary

Lifts two more module groups out of the mypy ignore_errors blanket:

  • locus.loop.* (~1.3k LOC: runner, router, nodes, react)
  • locus.reasoning.* (~3k LOC: causal, gsar, gsar_judge, gsar_evaluator, grounding, reflexion)

After this lands, only three groups remain on ignore_errors:

  • locus.rag.*
  • locus.memory.*
  • locus.hooks.builtin.* (held back — see below)

Notable: held-back module surfaces a real bug

While running the strict pass over locus.hooks.builtin.*, mypy surfaced that the built-in hooks (LoggingHook, GuardrailsHook, TelemetryHook) have method signatures inherited from a pre-event HookProvider API — they would TypeError at runtime when dispatched through HookRegistry.emit_*.

That's a behavioural fix, not a typing one. Tracked in #45 and migrated in a follow-up PR. Only the typing blanket on that one subpackage is preserved here — the rest of the audit goal is unaffected.

Test plan

  • hatch run typecheck — clean (150 source files)
  • hatch run test — 3,246 passed
  • pre-commit run --all-files — clean
  • CI: lint+typecheck on 3.11 and 3.14
  • CI: test matrix on 3.11–3.14
  • CI: pre-commit hooks

…batch 4)

Lifts ``locus.loop.*`` (~1.3k LOC across runner / router / nodes / react)
and ``locus.reasoning.*`` (~3k LOC across causal / gsar / gsar_judge /
gsar_evaluator / grounding / reflexion) out of the mypy
``ignore_errors`` blanket so they are now type-checked under the
project's strict defaults.

Specific fixes:

- ``reasoning.causal._detect_bidirectional``: build the pair tuple
  with explicit ``(str, str)`` typing so ``set[tuple[str, str]].add``
  type-checks (was inferred as the wider ``tuple[str, ...]``).
- ``reasoning.gsar_judge.StructuredOutputGSARJudge.judge``: cast the
  ``StructuredOutput.parsed`` field (typed as ``BaseModel | None``)
  back to ``JudgeOutput`` since the dynamic type is pinned by the
  schema we passed to ``parse_structured``.
- ``loop.router.RouterWithCustomConditions.route``: bind the
  ``model_copy`` result to a ``RouteDecision`` local so the return
  isn't ``Any``.
- ``loop.nodes.ToolNode``: declare the local ``events`` list with the
  same union as ``NodeResult.events`` so ``list``-invariance doesn't
  reject the otherwise-correct return.
- ``loop.runner``: drop a stale ``# type: ignore[assignment]``.

``locus.hooks.builtin.*`` is intentionally held back. The migration
surfaces a real correctness gap — the built-in hooks
(LoggingHook / GuardrailsHook / TelemetryHook) carry method
signatures from a pre-event ``HookProvider`` API and would TypeError
when dispatched through ``HookRegistry.emit_*``. That is a
behavioural fix and is tracked on its own follow-up PR.

Remaining batches: ``locus.rag.*``, ``locus.memory.*``,
``locus.hooks.builtin.*``.

Signed-off-by: Federico Kamelhar <federico.kamelhar@oracle.com>
@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label May 2, 2026
@fede-kamel fede-kamel merged commit 7a73c02 into main May 2, 2026
10 checks passed
@fede-kamel fede-kamel deleted the feat/mypy-migrate-batch4 branch May 2, 2026 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant