Skip to content

chore: resolve all pyright diagnostics and add a pyright CI job (#95) - #109

Merged
ngjunsiang merged 1 commit into
mainfrom
chore/95-pyright-gate
Oct 13, 2026
Merged

ngjunsiang merged 1 commit into
mainfrom
chore/95-pyright-gate

Conversation

@nycomp

@nycomp nycomp commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

What

Resolves every pyright diagnostic (#95) and adds a pyright job to .github/workflows/python-tests.yml following the nyxchange-timetable-v2 pattern (pyright as a dev dependency, poetry run pyright).

At HEAD of main, pyright 1.1.414 reported 55 errors (the issue counted 23; PRs #96–#108 added code since). After this PR: 0 errors, 0 warnings, and all 291 unit tests pass.

Source fixes (campus_python/)

  • None-guards on Optional values: LoginSession.user_id is UserID | None; the credentials lookups in _get_token_from_session and the auth token getter now raise AuthenticationError when it is None instead of indexing with a possible None. push_context skips the users-route fallback (and the cache put) when there is neither an embedded user nor a user id.
  • 401 hook feature-detect: with_user_session now installs the unauthorized hook via isinstance(client, CampusRequest) — matching the documented JsonClient contract ("callers must feature-detect") instead of assuming every client has the optional capability.
  • env.get(...) or "" after env.require("AUDIT_API_KEY") (require guarantees presence but returns None).
  • Retry-After parsing (audit/ratelimit.py): explicit None-check instead of relying on float(None) raising TypeError.
  • Payload typing: assignments.new() payload annotated dict[str, object].
  • Removed the dead pre-#857 fallback import of HttpHeader from campus.model in json_client — the lock now resolves campus-suite past the webauth move, so the fallback branch can never run and no longer type-checks.

Test fixes (tests/unit/)

  • MagicMock/cast where runtime swaps real objects for mocks (_session, client.post, _users accessed through stored mock references instead of the typed properties).
  • None-narrowing asserts after assertIsNotNone (pyright does not narrow through unittest assertions).
  • fake_send(prepared=…) renamed to request to match the Session.send signature.
  • Rule-scoped # pyright: ignore[reportCallIssue] / [reportMissingImports] on deliberate-negative pins (constructor-must-reject kwargs, the sys.path-shimmed errors import).

Verification

  • poetry run pyright — 0 errors, 0 warnings (pyright 1.1.414 via ^1.1.400 dev dep).
  • poetry run pytest — 291 passed.

Fixes #95

pyright 1.1.414 reports 0 errors against the repo (55 findings at HEAD,
up from the 23 in the issue - PRs #96-#108 added more). Source fixes:
None-guards on Optional user_id/token values, isinstance feature-detect
for the 401 hook per the JsonClient contract, dict[str, object] payload
typing, a Retry-After None-check, and removal of the dead pre-#857
campus.model fallback import. Test fixes: MagicMock casts where runtime
swaps in mocks, None-narrowing asserts, one parameter rename, and
rule-scoped pyright ignores on deliberate-negative pins. Adds pyright
(^1.1.400) as a dev dependency and a pyright job to python-tests.yml
following the nyxchange pattern.

Fixes #95
@ngjunsiang
ngjunsiang merged commit dae2d6c into main Oct 13, 2026
5 checks passed
@ngjunsiang
ngjunsiang deleted the chore/95-pyright-gate branch October 13, 2026 04:20
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.

chore: resolve 23 pyright diagnostics and enable a pyright CI job

2 participants