Skip to content

Clear all 18 mypy errors in detector.py (#432 session 6) - #446

Merged
squid-protocol merged 1 commit into
mainfrom
fix/432-detector-typing
Jul 25, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/432-detector-typing

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Part of #429/#432, one file per session. This session: `detector.py`.

  • `classes`: the regex-extracted class/struct/interface list (linked to functions via `parent_class_name` -- the exact structure investigated for # [EPIC] Enforce 5-Tier Knowledge Graph Hierarchy (Class-Level Rollup) #108/[EPIC] Enforce mypy Type Safety in CI #429's 5-tier hierarchy work) mixes `str`/`List[str]`/`int`/`float` per entry, widening to `object` under mypy. Added a `ClassInfo` `TypedDict`, split via inheritance into `_ClassInfoWithBounds` so the two `del cls["_start_line"/"_end_line"]` cleanup calls stay valid (mypy rejects deleting a required TypedDict key).
  • `DEFINITIONS`/`HANDSHAKE_REGISTRY` (class attrs): same heterogeneous-literal pattern as [REFACTOR] Fix root-cause type annotations causing mypy error fan-out #431's `RECORDING_SCHEMAS`/`LENS_CONFIG`.
  • `self.languages`: pinned `Dict[str, Any]` at first assignment, but a same-method reassignment in the AUTO-HEAL branch still re-narrowed it -- confirmed via `reveal_type` that a `.get()` right after actually returned `object`, not `Any`, despite the declared type. Wrapped the reassignment in `cast()` instead of fighting the narrowing.
  • Six missing annotations (`regex_telemetry`, `spatial_map`, `doc_buffer`, `all_satellites`, `satellites` x3).
  • Three `# type: ignore[union-attr]`, each confirmed provably safe at runtime already (existing `try/except` or `hasattr()` guard mypy just doesn't narrow through) before silencing -- not blanket-suppressed.

104 → 86 unique baseline entries.

Test plan

  • `detector.py`: `Success: no issues found in 1 source file`
  • Baseline regenerated in the minimal env `mypy-audit.yml` actually uses
  • `flake8`, `dead_key_audit.py --ci`, full `pytest tests/` (866 passed, 1 deselected, 1 pre-existing xfail) all clean

Root cause plus several smaller fixes:

- `classes`: the same-class regex-extracted class/struct/interface list
  (linked to functions via parent_class_name -- the exact structure
  investigated for #108/#429's 5-tier hierarchy work) mixes str/List[str]/
  int/float per entry, widening to "object" under mypy. Added a ClassInfo
  TypedDict, split via inheritance into a `_ClassInfoWithBounds` subclass
  so the two `del cls["_start_line"/"_end_line"]` calls (temporary
  spatial-bounds cleanup) stay valid -- mypy rejects deleting a required
  TypedDict key, only an optional/total=False one.

- `DEFINITIONS`/`HANDSHAKE_REGISTRY` (class attrs): same heterogeneous-
  literal pattern as #431's RECORDING_SCHEMAS/LENS_CONFIG. Dict[str, Any]
  / List[Dict[str, Any]] respectively.

- `self.languages`: pinned Dict[str, Any] at its first assignment, but a
  same-method reassignment (`self.languages = LANGUAGE_DEFINITIONS`, the
  AUTO-HEAL branch) still re-narrowed it to LANGUAGE_DEFINITIONS' own
  wide inferred type for the rest of that branch -- confirmed via
  reveal_type that a `.get()` right after actually returned `object`,
  not Any, despite the declared type. Wrapped that reassignment in
  cast(Dict[str, Any], ...) instead of fighting the narrowing.

- Six missing annotations: `regex_telemetry`/`spatial_map`
  (Dict[str, float] / Dict[str, List[int]]), `doc_buffer`/`all_satellites`/
  `satellites` x3 (List[str] / List[FunctionNode] x4).

- Three `# type: ignore[union-attr]`, each on a `.finditer()`/`.findall()`
  call already guarded by an existing try/except or hasattr() check mypy
  doesn't narrow through -- confirmed each is provably safe at runtime
  before silencing, not blanket-suppressed.

104 -> 86 unique baseline entries.

Verified: detector.py reports zero mypy errors ("Success: no issues
found in 1 source file"). flake8, dead_key_audit.py --ci, full pytest
suite (866 passed, 1 deselected, 1 pre-existing xfail) all clean.
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit 1808f3f into main Jul 25, 2026
26 checks passed
@squid-protocol
squid-protocol deleted the fix/432-detector-typing branch July 25, 2026 18:33
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.

1 participant