Skip to content

Annotate src/ for real: enable basedpyright type-strictness on source - #50

Merged
Aztec03hub merged 5 commits into
mainfrom
annotate-src-for-real
Jun 26, 2026
Merged

Annotate src/ for real: enable basedpyright type-strictness on source#50
Aztec03hub merged 5 commits into
mainfrom
annotate-src-for-real

Conversation

@Aztec03hub

Copy link
Copy Markdown
Owner

What

PR #47 reached basedpyright 0/0 by turning the inference-strictness rules OFF globally. This PR turns the high-value strictness rules back ON for the shipped package (src/) and adds real, accurate type annotations across all of src/claude_comms/ until basedpyright is clean again with those rules ON. Tests, dev scripts, and the build hook stay relaxed.

17 source files annotated. No runtime behavior changed; the full suite (1526 tests) still passes.

Config: which rules are ON for src/ vs OFF (and why)

Rather than "strictness ON globally + disabled-in-tests" (which would have newly lit up tools/, scripts/, and hatch_build.py with ~535 strictness diagnostics on files outside this PR's scope), the global block keeps strictness OFF exactly as #47 shipped, and a single [[tool.basedpyright.executionEnvironments]] root = "src" re-enables the high-value rules for the package only. Net effect: src/ is strict; tests/, tools/, scripts/, hatch_build.py keep their prior, relaxed treatment with zero collateral.

Turned ON for src/:

  • reportUnknownMemberType, reportUnknownVariableType, reportUnknownParameterType, reportUnknownArgumentType, reportUnknownLambdaType
  • reportMissingParameterType, reportMissingTypeArgument, reportUnannotatedClassAttribute
  • (all the correctness rules Clean all Python diagnostics to zero errors + warnings #47 kept ON are unchanged: reportMissingImports, reportArgumentType, reportReturnType, reportAttributeAccessIssue, reportOptional*, reportPossiblyUnbound, reportRedeclaration, reportUndefinedVariable, reportIndexIssue, reportInvalidCast, etc.)

Left OFF (with rationale):

  • reportAny / reportExplicitAny — the daemon speaks dynamic JSON/dict payloads (MQTT messages, MCP tool args, YAML config) where a precise static type does not exist; forcing these would push blanket casts everywhere, strictly worse than honest Any at the boundary. Correctness rules still flag real misuse.
  • reportPrivateUsage — 34 legitimate intra-package accesses of module-level underscore helpers (_registry, _publish_fn, _mqtt_subscriber, ...) the maintainers documented as idiomatic; renaming all to public is churn without correctness value.
  • reportMissingTypeStubs — 3rd-party libs (amqtt, textual, mcp, typer, rich) ship no stubs.
  • reportImplicitOverride, reportCallInDefaultInitializer, reportUnusedCallResult, reportImplicitStringConcatenation — style, not correctness.

Before / after (src/, per rule)

rule before after
reportUnknownArgumentType 326 0
reportUnknownVariableType 195 0
reportUnknownMemberType 154 0
reportUnannotatedClassAttribute 92 0
reportUnknownParameterType 79 0
reportMissingParameterType 50 0
reportMissingTypeArgument 46 0
reportUnknownLambdaType 3 0
total 945 (46 err / 899 warn) 0 / 0 / 0

tests/ stayed at 0/0/0 throughout. tools/+hatch_build.py remain at their pre-existing #47 baseline (unchanged by this PR — basedpyright is not a CI gate).

How it was annotated (quality)

Genuine types inferred from usage: precise where the shape is known (dict[str, list[str]], Path, Console, textual widget classes, aiomqtt.Client, local model classes), X | None over Optional, abstract types from collections.abc. dict[str, Any] only at genuine dynamic-JSON boundaries.

Suppression count went DOWN: removed 14 inert # type: ignore[no-untyped-def] (mypy codes basedpyright ignores) now that handlers are annotated; added exactly one new # pyright: ignore[reportUnnecessaryComparison] (a provably-dead defensive is None guard that cannot be deleted without altering control flow). 8 cast("dict[str, Any]" / "list[Any]", ...) for isinstance-narrowed dynamic JSON (pyright re-narrows annotated targets back to dict[Unknown, Unknown] after isinstance — the one genuinely unavoidable refinement), each commented inline. No real type bugs found.

Gates

  • basedpyright src/ -> 0 errors, 0 warnings, 0 notes; basedpyright tests/ -> 0/0/0
  • pytest -q -> 1526 passed (baseline), no new warnings
  • ruff check src/ tests/ -> clean; ruff format --check src/ tests/ -> clean

Scope: pyproject.toml + src/claude_comms/** only. No web/, tests/, or .svelte files touched.

🤖 Generated with Claude Code

Add real parameter/return/class-attribute/generic annotations to broker,
reactions, config, notifier, registry_store, log_exporter, presence so they
satisfy the inference-strictness rules. Annotations only; no behavior change.
dict[str, Any] used for dynamic MQTT/JSON/YAML payloads; isinstance-narrowed
JSON refined via documented cast().
Type the dynamic MCP/JSON dict payloads in mcp_summaries, mcp_server, and
mcp_tools (list[dict[str, Any]] result accumulators, dict[str, Any] returns,
class-attribute annotations). Annotations only; no behavior change.
Add ClassVar/DEFAULT_CSS annotations, compose() -> ComposeResult, event-handler
param/return types, typed reactive and instance attributes across the Textual
TUI widgets and screens. Annotations only; no behavior change.
Type the daemon/CLI surface: dict[str, Any] on dynamic config/JSON params,
Starlette Request/WebSocket handler signatures, Callable[...] callbacks, route
builder returns, and WS-adapter class attributes. Remove 14 inert mypy
# type: ignore[no-untyped-def] comments (basedpyright ignores mypy codes) now
that the handlers are properly annotated. Annotations only; no behavior change.
…ronment

Re-enable the high-value inference-strictness rules (reportUnknown*Type,
reportMissingParameterType, reportMissingTypeArgument, reportUnannotatedClassAttribute)
for the shipped package via a [[tool.basedpyright.executionEnvironments]] root = "src"
block, while the global block keeps them OFF so tests/, tools/, scripts/, and
hatch_build.py keep their prior relaxed treatment (zero collateral). reportAny/
reportExplicitAny and reportPrivateUsage stay OFF even for src (dynamic JSON payloads;
idiomatic intra-package _helper access). src now annotated to satisfy these: 0/0/0.
@Aztec03hub
Aztec03hub merged commit c0a2a76 into main Jun 26, 2026
8 checks passed
@Aztec03hub
Aztec03hub deleted the annotate-src-for-real branch June 26, 2026 02: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