Repository navigation
refactor: clear 82 type checker errors without behaviour change - #105
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ArchivistServicesbundle built by_build_services(); tests inject fakes throughservices=instead of assigning private attributes.Nonethe code never reaches:MicroBot._react, the messages CLI_apireturn type,GitMirrorcredentials, spinners, agent-labARGS.urllib.parse.quote,urllib.error,dict | Nonedefaults,_cfgstring defaults, Pillow'sImage.Resampling.make typecheck: 185 → 103 errors.make test-unitpasses. The remaining errors are container-only imports, the dynamic module loaders, OpenAI SDK overloads and status-dependent outcome fields; none are quick fixes.