Skip to content

Clear all 14 mypy errors in galaxyscope.py (#431 session 2) - #438

Merged
squid-protocol merged 1 commit into
mainfrom
fix/431-galaxyscope-observation-typing
Jul 25, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/431-galaxyscope-observation-typing

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Part of #429/#431, one file per session. This session: `galaxyscope.py` (plus two small signature fixes it depends on).

Four distinct fixes:

  • `_process_file_worker`'s `observation` dict was un-annotated; mypy inferred a narrow type from its first 4 keys (all str/dict), then flagged every later float/None assignment as incompatible. Annotated `Dict[str, Any]`, matching the function's own return type. Resolved 10/14.
  • `import importlib` without `import importlib.util` -- worked at runtime only by accident (something else transitively imported it first).
  • `self.neighborhood_tracker = defaultdict(int)` had no inferable key type. Annotated `DefaultDict[str, int]`.
  • `run_xray_audit`/`run_firewall_audit`'s `config: Optional[ResolvedConfig]` signatures didn't match their own docstrings, which already documented dual ResolvedConfig-or-dict support ("only `.get()` works uniformly across both"). Broadened to `Optional[Union[ResolvedConfig, Dict[str, Any]]]` in both files -- `galaxyscope.py`'s call site was already correct.

187 → 173 unique baseline entries.

Test plan

Four distinct fixes:

- _process_file_worker's `observation` dict: un-annotated literal dict
  with 4 initial str/dict-valued keys, but later code paths assign
  float/None values into it too. Annotated as Dict[str, Any] (matching
  the function's own declared return type) instead of leaving mypy to
  infer a narrow type from the literal's first 4 keys. Resolved 10 of
  the 14 -- the "Collection[str]"-family fan-out this session's errors
  were mostly made of.
- `import importlib` without `import importlib.util`: worked at runtime
  only because something else transitively imported importlib.util
  first. Changed to `import importlib.util` directly.
- `self.neighborhood_tracker = defaultdict(int)`: mypy can't infer a key
  type from an empty defaultdict. Annotated DefaultDict[str, int],
  matching how it's actually keyed (str(path_obj.parent)).
- `run_xray_audit`/`run_firewall_audit`'s `config: Optional[ResolvedConfig]`
  signatures: both functions' own docstrings already documented that the
  caller may hand over either a ResolvedConfig or a plain dict ("only
  .get() works uniformly across both") -- the signature just never said
  so. Broadened to Optional[Union[ResolvedConfig, Dict[str, Any]]] in
  both binary_anomaly_detector.py and supply_chain_firewall.py to match
  the already-intentional, already-documented behavior; galaxyscope.py's
  call site (passing self.config, a plain dict) was correct as-is.

187 -> 173 unique baseline entries. Baseline regenerated in the same
minimal environment mypy-audit.yml uses (mypy + PyYAML only), per the
docstring note added after #436's environment mismatch.

Verified: galaxyscope.py, binary_anomaly_detector.py, and
supply_chain_firewall.py all report zero mypy errors after this change.
flake8, dead_key_audit.py --ci, and 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 85dfab1 into main Jul 25, 2026
26 checks passed
@squid-protocol
squid-protocol deleted the fix/431-galaxyscope-observation-typing branch July 25, 2026 17:17
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