Skip to content

chore: replace mypy with pyrefly - #1963

Merged
spydon merged 4 commits into
mainfrom
chore/replace-mypy-with-pyrefly
Nov 4, 2026
Merged

spydon merged 4 commits into
mainfrom
chore/replace-mypy-with-pyrefly

Conversation

@spydon

@spydon spydon commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

What

Replaces mypy with pyrefly (1.4, stable since 1.0) as the type checker for every package. Resolves SDK-2624 and also covers SDK-2622, because all packages now share one config.

Configuration

  • pyrefly.toml at the repository root holds the shared rules. Each package's pyproject.toml has a small [tool.pyrefly] section that extends it and sets project-includes and search-path.

  • It uses the strict preset and required-version = ">=1.4.0,<2.0.0". It does not pin python-version, so each CI job type checks against its own interpreter (3.11 to 3.14).

  • enabled-ignores = ["pyrefly"]: only # pyrefly: ignore[code] suppresses errors, and unused-ignore (part of strict) flags stale ones.

  • Rules enabled on top of strict:

    Group Rules
    mypy strict equivalents unannotated-parameter, unannotated-return, unannotated-attribute, no-any-return, untyped-function-decorator, untyped-class-decorator, untyped-import
    Public API implicit-reexport, implicit-import, unresolvable-dunder-all, deprecated
    TypedDict and correctness not-required-key-access, incompatible-comparison, invalid-cast, string-as-iterable, implicit-abstract-class, uninitialized-instance-variable, non-exhaustive-match
    Dead code and redundancy redundant-cast, redundant-condition, unnecessary-comparison, unnecessary-type-conversion, unreachable-except-clause, unreachable-match-case, misplaced-ignore
  • make <pkg>.pyrefly replaces make <pkg>.mypy, and make <pkg>.tests (which CI runs) now type checks with pyrefly. utils is added to the CI matrix, because it was never type checked in CI before. mypy and pylsp-mypy are removed from the dependency groups, and storage's mypy group is renamed to typecheck.

Fixes found by pyrefly

  • __exit__/__aexit__ on the auth, postgrest, storage, supabase and utils clients were typed with type[Exception]. async with client: now type checks when a BaseException such as CancelledError is raised.
  • supabase.__all__ listed SupabaseAuthClient, ASupabaseAuthClient and SupabaseException, which no longer exist, so from supabase import * raised AttributeError.
  • supabase_auth and realtime now re-export their public names explicitly, so strict type checkers in user projects accept from supabase_auth import AsyncSupabaseAuthClient.
  • SupabaseAuthHttpClient is generic over its session manager, so subclasses no longer narrow a mutable attribute unsoundly.
  • Realtime Presence/PresenceMeta declare extra_items=Any (PEP 728) to match the pydantic extra="allow" they already had, so user presence keys type check. RealtimeClientOptions is closed=True, so it can be unpacked into connect_once.
  • FunctionsClient.invoke accepts bytearray in its signature, matching what it already handled at runtime.
  • The async supabase client no longer sets _postgrest/_storage/_functions. Those attributes were never read.
  • @override was added where methods override a parent, plus missing annotations, mostly in tests.

Notes

  • make auth.build-sync currently produces broken _sync tests (it imports SyncHttpxSession, which doesn't exist, and drops helpers). The _sync auth test edits here were therefore made by hand to mirror _async.
  • Five suppressions remain, each with a specific code: the intentionally deprecated postgrest SyncClient test, get_event_loop_policy in the storage test helper, ChannelEvents.join shadowing str.join, and a test that passes an invalid body on purpose.

Testing

  • make pyrefly: 0 errors in all seven packages.
  • make auth.tests, make postgrest.tests and make storage.tests with infra: all pass. Functions and supabase unit tests pass.
  • make realtime.tests: 38 passed. The 5 errors in test_reconnection.py are a port 55555 bind failure that also happens on main locally.

@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Explain Change →

Summary

Summary by CodeRabbit

  • New Features
    • Function requests now accept bytearray bodies, converted to binary data before sending.
    • Presence data can include additional fields.
  • Bug Fixes
    • Auth state changes no longer clear cached service clients.
    • Functions error handling now consistently constructs base errors.
  • Chores
    • Replaced mypy checks with Pyrefly across packages and updated related project configuration.

The pull request replaces mypy with Pyrefly in repository and package Make targets and configuration. It adds type annotations across the auth, Functions, PostgREST, Realtime, Storage, Supabase, and utility packages. It also changes Functions request-body and region handling, PostgREST column inference, selected Supabase exports and auth-event handling, and Realtime typed-dictionary declarations. Tests receive type annotations and several assertion updates.

Possibly related PRs

Change: Other

Merge Risk: Minimal · up to 433fb

The type-checker migration has no established merge-blocking regression. Mapping-row serialization compatibility remains unverified, but the relevant serialization behavior is unchanged.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Type checking now runs on pyrefly with a shared strict config in pyrefly.toml
that every package extends. On top of the strict preset it enables the mypy
strict equivalents plus extra checks for re-exports, TypedDict access,
deprecated APIs and dead code.

Fixes the type errors pyrefly found, including context managers typed with
Exception instead of BaseException, stale names in supabase.__all__ and
implicit re-exports in supabase_auth and realtime.
Pinning a single python-version made pyrefly resolve imports for that version
only, so jobs on other interpreters could fail on missing version-specific
dependencies. Each job now checks against its own interpreter. This also
installs the utils extras for its type check.
@spydon
spydon force-pushed the chore/replace-mypy-with-pyrefly branch from 78c1956 to 9d6a448 Compare November 4, 2026 11:31
utils was missing from the test matrix, so its type errors were never caught
in CI. Its tests target only runs pyrefly, so the job skips the coverage
upload.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional comments: 1
src/postgrest/src/postgrest/request_builder.py-58-59: 1

58-59: Minor · Potential issue · Low value

Unverified finding
We couldn't verify this from the code. It is shown for review, not as a verified issue.

_unique_columns now collects keys only from dict rows, although the supplied JSON alias also permits other mappings. A supported non-dict mapping row may therefore have its column names omitted from an insert or upsert request.

PostgREST may omit the supplied field and insert a default value instead.

This can occur when: A bulk insert or upsert contains a non-dict mapping with a key absent from the dict rows, and the request serializer supports that mapping.

Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: eae63d2d-7741-4f06-91d0-1041f2a9962f
Commits

Reviewing files that changed from the base of the PR and between 78c1956 and 9d6a448.

Files ignored due to path filters: 1
  • uv.lock is excluded by !**/*.lock
Files selected for processing: 9
  • AGENTS.md
  • src/auth/pyproject.toml
  • src/functions/pyproject.toml
  • src/postgrest/pyproject.toml
  • src/postgrest/src/postgrest/client.py
  • src/postgrest/src/postgrest/request_builder.py
  • src/realtime/pyproject.toml
  • src/realtime/src/realtime/channel.py
  • src/utils/src/supabase_utils/http/io.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.

The JSON type allows any Mapping, but the column list only read keys from
dict rows, so other mappings lost their columns in bulk inserts and upserts.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional comments: 1
src/postgrest/src/postgrest/request_builder.py-60-60: 1

60-60: Minor · Potential issue · Low value

Unverified finding
We couldn't verify this from the code. It is shown for review, not as a verified issue.

_unique_columns now recognizes non-dict mappings, but the insert/upsert request-body serializer may not encode those same rows. The new MappingProxyType test checks column inference without checking whether such a row can be sent.

Column inference succeeds, but constructing or sending the request raises a serialization error instead of inserting the row.

This can occur when: An insert or upsert receives a MappingProxyType row, as in the new test.

Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5cc0ed43-ff3d-4f00-b422-89c8872f3b33
Commits

Reviewing files that changed from the base of the PR and between 9d6a448 and 433fbd9.

Files selected for processing: 3
  • .github/workflows/ci.yml
  • src/postgrest/src/postgrest/request_builder.py
  • src/postgrest/tests/test_unique_columns.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 1 remain after this review.

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