Skip to content

Replace the mypy ban with a strong-typing policy - #245

Merged
ptr727 merged 5 commits into
developfrom
feature/python-typing-policy
Jul 6, 2026
Merged

Replace the mypy ban with a strong-typing policy#245
ptr727 merged 5 commits into
developfrom
feature/python-typing-policy

Conversation

@ptr727

@ptr727 ptr727 commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Resolves the mypy spec question raised by the aiopurpleair / homeassistant-purpleair audits, and fixes an internal hub contradiction.

The contradiction: CODESTYLE.md banned mypy ("not used here - don-t introduce it"), while AGENTS.md:247 and catalog/snippets/vscode/python.jsonc both ship the mypy VS Code extension. The ban also entered undocumented - carried from the PyPiLibrary sample during the CODESTYLE consolidation (f526b55), with no recorded rationale.

The policy (CODESTYLE.md):

  • Objective: strong-typed, deterministic code.
  • pyright strict on first-party code is the required baseline - Pylance embeds pyright, so the editor and CLI/CI run the same engine and never disagree.
  • Relax third-party strictness only where a dependency has no usable types (e.g. pandas), via a targeted commented ignore, never blanket.
  • mypy is allowed, not banned; required for a Home Assistant integration (platinum strict-typing), useful for a pydantic library (pydantic.mypy plugin). Multiple tools by purpose is normal - the .NET side pairs CSharpier + dotnet format the same way.

Spec (spec/project-types.json): default vs HA Python profiles - HA standalone .ruff.toml/pyrightconfig.json is exempt (not drift), mypy --strict expected for HA.

AGENTS.md:247 and the catalog snippet already include mypy, so deleting the ban reconciles all three. Fuller homeassistant-type checks (manifest/hacs/quality_scale, the test-matrix tracker) remain follow-up per the audits.

The objective is strong-typed, deterministic code. Make pyright strict on first-party code the required baseline (Pylance embeds pyright, so editor and CLI/CI run the same engine and stay consistent), relaxing third-party strictness only where a dependency has no usable types. Delete the CODESTYLE mypy ban - it contradicted AGENTS.md and the catalog VS Code snippet, which already ship the mypy extension - and allow mypy as an additional checker, required for a Home Assistant integration (platinum strict-typing) and useful for a pydantic library (the pydantic.mypy plugin). Multiple tools serving distinct purposes is normal, like CSharpier + dotnet format on the .NET side. Record the default vs HA Python profiles in spec/project-types.json (HA standalone configs are exempt, not drift; mypy --strict expected).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 6, 2026 04:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR reconciles the repo's Python typing/tooling guidance by removing the implied mypy ban and formalizing a "strong typing" policy that treats pyright strict as the baseline, with mypy permitted (and required for Home Assistant integrations).

Changes:

  • Updates CODESTYLE.md Python guidance to define a strong-typing baseline (pyright strict) and allow mypy as an additional checker (and HA requirement).
  • Updates spec/project-types.json to reflect the new typing policy and Home Assistant exemptions/conventions.
  • Adds pydantic to cspell.json to avoid false positives introduced by the updated documentation.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
spec/project-types.json Aligns the audit/spec checks with the new pyright/mypy policy and HA conventions/exemptions.
cspell.json Adds terminology used by the updated typing policy text.
CODESTYLE.md Replaces the mypy-ban language with a strong-typing policy and documents when mypy is appropriate/required.

Comment thread CODESTYLE.md Outdated
Adopt the more natural adjective form per review. The pyright strict = ["src"] example is correct as written - pyright's strict config key is an array of path globs (in production in aiopurpleair's [tool.pyright], and already documented at CODESTYLE.md:423); the boolean strict is mypy's.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread CODESTYLE.md Outdated
Move [mypy-link] into its alphabetical slot (after latest-link, before pep-0257-link) in the external reference block. Addresses Copilot review.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread CODESTYLE.md Outdated
Comment thread spec/project-types.json Outdated
Keep python.config.placement a single-form letter check (pyproject canonical) and delegate the Home Assistant standalone-config exception to ha.python.conventions, rather than listing two acceptable forms in one letter check. Qualify the mypy toolchain-table config cell so it does not hard-code pyproject for HA repos. Addresses Copilot review.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread CODESTYLE.md
The clean-compile now names the repo's mypy command (e.g. uv run mypy src) where mypy is used, matching the Type checking policy that says mypy joins the clean-compile. Addresses Copilot review.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@ptr727
ptr727 merged commit 7920433 into develop Jul 6, 2026
7 checks passed
@ptr727
ptr727 deleted the feature/python-typing-policy branch July 6, 2026 04:34
ptr727 added a commit that referenced this pull request Jul 7, 2026
Two-phase promotion of the accumulated governance work on `develop` to
`main`. Carries #244-#251:

- #244 Foundational Principles (the model's governing *why*)
- #245 Replace the mypy ban with a strong-typing policy
- #246 aiopurpleair + homeassistant-purpleair audit reports
- #247 Catalog the 14 backlog repos; add the `eda` type and
`releaseTrigger: none`
- #248 Branch-conditional Docker platforms (multi-arch main, amd64
elsewhere)
- #249 Retire the both-branch matrix for symmetric single-branch
self-release
- #250 Declare workflow YAML as LF and validate line endings in CI
- #251 Extend line-ending governance to pattern files and catalog
snippets

All commits were reviewed and CI-green on their individual develop PRs.
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.

2 participants