Skip to content

Upgrade ty to 0.0.69 and fix typing bugs it newly catches - #97

Draft
davegaeddert wants to merge 1 commit into
masterfrom
claude/funny-mendel-dpl351
Draft

Upgrade ty to 0.0.69 and fix typing bugs it newly catches#97
davegaeddert wants to merge 1 commit into
masterfrom
claude/funny-mendel-dpl351

Conversation

@davegaeddert

Copy link
Copy Markdown
Member

Summary

Bumps the pinned ty type checker from 0.0.65 to 0.0.69 (checked the changelog for 0.0.66–0.0.69) and fixes several latent typing bugs the newer version's more accurate typeshed bundling and stricter checking newly caught — rather than just silencing them with more ignores.

  • plain/plain/test/client.py: SimpleCookie[str] was an invalid subscript — SimpleCookie isn't generic in typeshed (it hardcodes BaseCookie[str]). Dropped the subscript.
  • plain/plain/utils/datastructures.py: ImmutableList was declared as a plain tuple subclass despite being used as ImmutableList[T] everywhere. Made it properly generic: class ImmutableList[T](tuple[T, ...]).
  • plain-postgres/plain/postgres/meta.py / query.py: fixing ImmutableList's genericity made Meta's field-collection properties correctly typed for the first time, which surfaced ~37 further errors from internals code that duck-types across heterogeneous Field subtypes (base Field[T] doesn't declare remote_field/required/clean/etc., which only exist on subclasses, and several call sites rely on runtime type guards ty can't see through). Left those collections as bare ImmutableList rather than forcing a parametrization the field hierarchy doesn't actually support — except related_objects, which is genuinely homogeneous (ForeignObjectRel) and stays precisely typed. Also collapsed a set of @overload stubs in meta.py that had gone dead (all branches now return the same type).
  • plain-admin/plain/admin/views/{base,objects,viewsets}.py: AdminViewset.get_views() wired cross-linked URLs onto view classes via dynamic attribute assignment, suppressed with # ty: ignore[unresolved-attribute]. Hoisted the five duplicated URL-getter stub methods (previously copy-pasted across AdminListView/AdminCreateView/AdminDetailView/AdminUpdateView/AdminDeleteView) onto the shared AdminView base class, and typed get_views() against AdminView instead of the generic View, so the assignments type-check for real and the ignore comments are gone.
  • plain-admin/plain/admin/cards/base.py: removed one stale, now-unused blanket # type: ignore.
  • plain-auth/plain/auth/test.py: the test login_client helper built a cookie-attributes dict that didn't type-check against Morsel.update()'s signature. Rebuilt it on top of Response.set_cookie() — the same path plain.sessions's middleware uses in production — which also fixes a real staleness bug where the test helper had drifted and stopped setting httponly/samesite.

Net effect: type-ignore count across the workspace drops from 160 to 153, with zero new ignores added.

Test plan

  • ./scripts/type-validate — 27/27 paths pass, no diagnostics
  • ./scripts/fix — ruff check/format clean (oxlint/oxfmt couldn't be reinstalled in this sandbox due to a proxy/TLS limitation unrelated to this change; no non-Python files were touched)
  • ./scripts/test (full suite, local Postgres) — all packages pass
  • /simplify — ran a 4-angle review (reuse/simplification/efficiency/altitude) over the diff and applied the fixes it surfaced (collapsed dead overloads, restored related_objects's precise type, reused Response.set_cookie() instead of hand-rolling cookie attributes)

Note: I wasn't able to route out-of-scope review findings to PullApprove — the PullApprove5 connector didn't come online in this session. There weren't any left to route in the end; everything the review turned up got fixed.


Generated by Claude Code

Bumps the pinned `ty` type checker from 0.0.65 to 0.0.69. The newer
version's more accurate typeshed bundling and stricter checking
surfaced several latent bugs that were previously masked:

- `SimpleCookie[str]` was an invalid subscript (SimpleCookie isn't
  generic in typeshed); drop it.
- `ImmutableList` was declared as a plain `tuple` subclass despite
  being used as `ImmutableList[T]` everywhere; make it properly
  generic (`class ImmutableList[T](tuple[T, ...])`).
- Fixing ImmutableList's genericity made plain-postgres's Meta
  properties correctly typed for the first time, which surfaced ~37
  further errors from code that duck-types across heterogeneous
  Field subtypes. Left those collections as bare `ImmutableList`
  (except `related_objects`, which is homogeneous and stays precisely
  typed) rather than forcing full parametrization that the field
  hierarchy doesn't support yet.
- plain-admin's AdminViewset wired cross-linked URLs onto view
  classes via dynamic attribute assignment suppressed with
  `# ty: ignore[unresolved-attribute]`. Hoisted the five duplicated
  URL-getter stub methods onto the shared AdminView base class and
  typed `get_views()` against AdminView instead of the generic View,
  so the assignments type-check for real and the ignores are gone.
- plain-auth's test `login_client` helper built a cookie-attributes
  dict that didn't type-check against Morsel's update() signature;
  rebuilt it on top of `Response.set_cookie()` (the same path
  `plain.sessions`'s middleware uses), which also fixes a staleness
  bug where the test helper omitted `httponly`/`samesite`.

Net effect: type-ignore count across the workspace drops from 160 to
153, with zero new ignores added. `./scripts/type-validate` and the
full test suite pass.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EzceyCD3hNuNjQwi1pLDej
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