Skip to content

ci(mypy): restore mypy with HA follow_imports=skip boundary#187

Merged
Artic0din merged 2 commits into
devfrom
chore/restore-mypy-with-ha-stubs
May 28, 2026
Merged

ci(mypy): restore mypy with HA follow_imports=skip boundary#187
Artic0din merged 2 commits into
devfrom
chore/restore-mypy-with-ha-stubs

Conversation

@Artic0din

Copy link
Copy Markdown
Owner

Problem

mypy was stripped from CI (#176 deferral) because pytest-homeassistant-custom-component pins HA to 2023.7.3, whose stubs lag the APIs the code targets — producing 30+ false positives.

Approach

Per constitution §14 (systemic) + §19 (platform conventions): treat homeassistant.* + openelectricity.* as Any via follow_imports = skip in mypy.ini. Correct boundary for a HACS integration — HA API correctness is runtime-validated, not mypy's job. Our own logic stays fully checked.

Scope

Restores Mypy CI step. Real non-HA type errors (if any) fixed in follow-up commits on this branch.

Risk

  • Workflow change — adds back mypy gate
  • everything else N/A

Reviewer focus

For @codex: is follow_imports = skip on HA the right call vs pinning a newer HA? (It is — pytest-hcc can't be bumped past 2023.7 and the smoke tests need it.)

Constitution check

  • Root cause identified (stale HA stub pin, not our code)
  • Systemic fix (one mypy.ini rule vs 11 ignores)
  • No new tech debt

Root cause of the earlier mypy hell: pytest-homeassistant-custom-component
pins HA to 2023.7.3, whose stubs lag the APIs the code targets
(OptionsFlowWithReload, current SelectorOptionsType). mypy analysing those
stale internals produced 30+ false positives.

Fix per constitution §14 (systemic over local) + §19 (platform conventions):
treat `homeassistant.*` and `openelectricity.*` as Any via
`follow_imports = skip` in mypy.ini — the correct boundary for a HACS
integration whose HA API correctness is validated at runtime, not by mypy.
Our own logic stays fully type-checked.

Restores the Mypy CI step. Expect only real, non-HA type errors to remain
(arg-type, no-redef, var-annotated, call-overload) — fixed in follow-up
commits on this branch.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 622e136be2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .github/workflows/ci.yml
The #170 auto-merge cascade left full inline copies of the
_apply_options_to_state projector in BOTH __init__ and rebuild_engine,
each running alongside the actual projector call — double application
plus 5 no-redef errors (attributes assigned twice with annotations)
and a latent bug where _api_key was read options→data via _resolve_str
then immediately overwritten by a data-only read.

- __init__: remove the dead inline DWT/CDR + providers + amber_mode +
  named_comparator block (~75 lines); keep typed placeholders + the
  single projector call. Fixes 5 no-redef.
- rebuild_engine: remove the dead inline provider-rebuild block
  (~145 lines); keep only the strict=False projector call it already
  made. Fixes 5 Mapping-vs-dict arg-type errors.
- _api_key: single options→data read via _resolve_str (drops the
  data-only override that silently ignored options-flow key edits).
- rebuild_per_tick_explanation: param retyped dict[str,dict[str,Any]]
  → ProviderBlock to match _build_providers_block + build_explanation.
  Fixes 2 arg-type errors.

explanation.py:
- _won_bullets helpers: replace `.get(key, {})` (which poisons the
  ProviderSnapshot TypedDict into a union) with None-guarded access.
  Fixes call-overload + var-annotated.

Net: 220 fewer lines, projector is now the single source of truth as
its docstring always claimed, 12 of 14 mypy errors fixed by real
code repair (not suppression).
@Artic0din

Copy link
Copy Markdown
Owner Author

Addressed in the same PR — commit 3c617e2 lands all 14 type fixes (de-dup of the duplicated projector blocks + ProviderBlock retype + explanation.py None-guards). CI is green on the final commit (ci/validate/security all pass), so the gate is not left red. The review fired against the first commit (gate-restore) before the fix-commit landed.

@Artic0din Artic0din merged commit 6429732 into dev May 28, 2026
4 checks passed
@Artic0din Artic0din deleted the chore/restore-mypy-with-ha-stubs branch May 28, 2026 03: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