Skip to content

chore: use built-in generic types in annotations - #1889

Merged
spydon merged 1 commit into
mainfrom
chore/pep585-annotations
Oct 30, 2026
Merged

spydon merged 1 commit into
mainfrom
chore/pep585-annotations

Conversation

@spydon

@spydon spydon commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Why

The root Ruff config ignored UP006 and UP035, so annotations still used typing.List, Dict, Tuple, Type and similar, plus imports that typing deprecated in Python 3.9. Built-in generics (list[str], dict[str, Any]) work at runtime on every Python version we support (3.9 and later, PEP 585), so the ignores no longer serve a purpose.

What changed

  • Removed UP006 and UP035 from the root Ruff ignore list.
  • Ran Ruff's fixes for both rules: 283 annotations now use built-in generics, and 97 deprecated typing imports now come from collections.abc or the built-ins.
  • Regenerated the _sync trees with build-sync.

No behavior changes. Every edit is a Ruff fix and changes only which name an annotation uses.

Why it is safe on Python 3.9

Ruff counts the UP006 fix as unsafe because an annotation evaluated at runtime (pydantic fields, type aliases, cast) now evaluates a different expression. On 3.9 and later, list[...] and the others are valid at runtime, so I checked:

  • Every module of every package imports cleanly on Python 3.9.6.
  • mypy passes for all six packages.
  • On Python 3.9: functions 113 passed, supabase 46 passed, postgrest 539 passed (against Docker).
  • storage, auth and realtime on 3.9 are left to the CI matrix. Their local Docker stack could not start next to another Supabase stack running on the same ports.

@spydon
spydon requested a review from o-santi as a code owner October 30, 2026 17:09
@spydon
spydon merged commit 1ef4688 into main Oct 30, 2026
46 checks passed
@spydon
spydon deleted the chore/pep585-annotations branch October 30, 2026 19:40
spydon added a commit that referenced this pull request Nov 2, 2026
Stacked on #1889. Review that first; this PR only contains the last
commit.

## Why

A bare `# type: ignore` silences every mypy error on its line, including
new ones introduced later. A bare `# noqa` does the same for Ruff. With
47 bare `type: ignore` comments and 11 bare `noqa` comments, a new bug
on one of those lines would go unnoticed.

## What changed

- Each bare `# type: ignore` now names the codes mypy actually reports
on that line, for example `# type: ignore[method-assign]`. I found them
by removing each comment, running mypy and putting back exactly the
codes it reported. All of them were still needed, and none were removed.
- The bare `# noqa` comments are gone, replaced by real fixes:
- The `supabase_auth/__init__.py` re-exports use `X as X`, the same as
realtime since #1887.
- `AsyncGoTrueBaseAPI._request` uses `raise handle_exception(e) from e`,
which `B904` asks for. This keeps the original HTTP error as `__cause__`
instead of `__context__`.
- Enabled `PGH003` and `PGH004` in the root Ruff config, so new bare
`type: ignore` and `noqa` comments fail CI. Combined with
`warn_unused_ignores`, which auth, postgrest, realtime and storage
already enable, these comments now have to stay accurate.

## Verification

- Ruff passes on all of `src/`, and mypy passes for all six packages.
- The `_sync` trees were regenerated with `build-sync`.
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