Skip to content

refactor: clear 82 type checker errors without behaviour change - #105

Merged
arthware-dev merged 4 commits into
mainfrom
chore/type-fixes
Sep 21, 2026
Merged

arthware-dev merged 4 commits into
mainfrom
chore/type-fixes

Conversation

@arthware-dev

@arthware-dev arthware-dev commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Archivist: wire its services into one ArchivistServices bundle built by _build_services(); tests inject fakes through services= instead of assigning private attributes.
  • Declarations that allowed a None the code never reaches: MicroBot._react, the messages CLI _api return type, GitMirror credentials, spinners, agent-lab ARGS.
  • Imports and annotations: urllib.parse.quote, urllib.error, dict | None defaults, _cfg string defaults, Pillow's Image.Resampling.

make typecheck: 185 → 103 errors. make test-unit passes. The remaining errors are container-only imports, the dynamic module loaders, OpenAI SDK overloads and status-dependent outcome fields; none are quick fixes.

The archivist declared ten collaborators as `X | None = None` in the
constructor and assigned them in `start()`. None was never a valid
state once the bot ran, but the type said it was: every use was
reported as a possible None access, and tests reached into the private
attributes to swap in fakes.

- `ArchivistServices`, a frozen dataclass, holds them. `classifier` and
  `mirror` stay optional because they are absent without an AI endpoint
  or Forgejo; everything else is required.
- `_build_services()` is the wiring that used to live inline in
  `start()`; `_init_mirror()` becomes `_build_mirror()` and returns the
  mirror instead of setting it.
- The constructor takes `services=` for callers that never start the
  bot. The archivist tests use it instead of assigning privates.

No behaviour change.
- Call `urllib.parse.quote` instead of `urllib.request.quote`, which
  only works because `urllib.request` happens to re-export it.
- Import `urllib.error` where `docker.py` catches `HTTPError`; it was
  reachable only as a side effect of importing `urllib.request`.
- Declare `env` and `headers` parameters that default to None as
  `dict | None`.

No behaviour change.
The type checker reported these as possible None accesses because
their declarations allowed a state the code never reaches.

- `MicroBot._react` already ignores an empty event id; its parameter
  is now `str | None`, matching the callers that pass a reply id.
- The messages CLI `_api` helper returns `tuple[int, dict[str, Any]]`.
  Without it the error branch made the body look like `dict[str, str]`
  and every `.get()` chain on a Matrix response read as `str`.
- The archivist's topic welcome parses the room name once and branches
  on the result, instead of re-parsing after the kind check.
- `GitMirror` reads its credentials through `_setup_creds`, which
  raises if `ensure_setup()` has not succeeded; every caller already
  returns early in that case.
- agent-lab `lab-api` declares `ARGS` as the Namespace `main()` sets.

No behaviour change.
- Pass string defaults to `Stack._cfg`, which returns `str`; the two
  wiki settings render the same `"true"` and `"180"` as before.
- `stack doctor` hands `check_release` an empty string when there is no
  release tag, which it already reads as "no release".
- `_format_size` takes a float, since it divides the value in place.
- The spinners declare their thread at class level; `__enter__` starts
  it and `__exit__` joins it, so the None placeholder is gone.
- `disable_thinking` falls back to a module-level no-op logger rather
  than redefining its own parameter.
- Read a module docstring as `__doc__ or ""`, and use
  `Image.Resampling.BICUBIC`, the name Pillow types.

No behaviour change.
@arthware-dev
arthware-dev merged commit 2001dea into main Sep 21, 2026
1 check passed
@arthware-dev
arthware-dev deleted the chore/type-fixes branch September 21, 2026 15:53
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