Skip to content

chore: unify ruff config and enable more lint rules - #1887

Merged
spydon merged 1 commit into
mainfrom
chore/unify-ruff-config
Oct 30, 2026
Merged

spydon merged 1 commit into
mainfrom
chore/unify-ruff-config

Conversation

@spydon

@spydon spydon commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Why

realtime, postgrest and supabase each had their own [tool.ruff.lint] section. Ruff does not merge those with the root config, so any rule added at the root never reached those packages. postgrest and realtime also had bugbear (B) and ANN2 turned off and ignored F401, F841 and E712. That is how the missing raise fixed in #1881 got through: PLW0133 would have caught it, but it could not have been enabled for postgrest.

What changed

Config

  • The three package configs are replaced with extend = "../../pyproject.toml", so every package uses the root rules. Each package keeps its own project root, so import sorting (first-party vs third-party) is unchanged.
  • New rules in the root config, all of which were clean or nearly clean:
Rule Catches
PLE Pylint errors, code that fails at runtime
PLW Pylint warnings, including a missing raise (PLW0133)
PIE Unnecessary statements and duplicate class fields
LOG Logging misuse
FLY Static str.join that should be an f-string
YTT Wrong sys.version comparisons
PT014 Duplicate pytest.mark.parametrize cases
RUF100 Stale # noqa directives

Fixes for what the rules found

  • postgrest:
    • raise APIError(...) from e when the error body fails validation, so the original error stays in the chain (B904).
    • text_search no longer uses a mutable {} default (B006).
    • BasePostgrestClient no longer inherits from ABC; it has no abstract methods (B024).
    • Removed a duplicate parametrize case in test_utils.py (PT014), a dead field_validator import and other unused imports and variables.
  • realtime:
    • Re-exports in __init__.py use X as X so they count as public.
    • Tests compare to True and False with is.
    • Removed unused variables and imports.
  • storage: Removed global statements that never assign.
  • auth, functions, storage: Removed # noqa comments that no longer suppress anything.
  • Return type annotations (ANN2): Added to postgrest and realtime, mostly -> None on tests. mypy only checks functions that have annotations, so it now also checks those test bodies. Fixing what it found:
    • range_gt, range_gte, range_lt, range_lte, range_adjacent and the underlying sl, sr, nxl, nxr, adj were typed Tuple[int, int], but Postgres ranges are often dates or timestamps, and the integration tests pass timestamp strings. They now take Tuple[FilterValue, FilterValue]. This widens the accepted type, so existing callers are unaffected.
    • Tests narrow maybe_single() results with assert res is not None and the CSV response with isinstance.

Not included

RUF006 (fire-and-forget asyncio.create_task) has 6 hits in realtime and the supabase client, and ASYNC has 2 blocking open() calls in async storage code. Fixing those changes behavior, so they will come in a separate PR.

Verification

  • ruff check passes on all of src/.
  • mypy passes for postgrest, realtime, storage and supabase.
  • postgrest: the full suite against Docker passes, 539 of 539.
  • realtime: the tests that need no server pass, 28 of 28.
  • The _sync trees match build-sync output, and uv.lock is unchanged.

@spydon
spydon merged commit 351c7ee into main Oct 30, 2026
46 checks passed
@spydon
spydon deleted the chore/unify-ruff-config branch October 30, 2026 16:49
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`.
spydon added a commit that referenced this pull request Nov 6, 2026
…y rules (#2008)

## Summary

SDK-2910. The shared ruff config from #1887 (SDK-1689) was lost when v3
became `main` in #1370. Every package except `utils` had its own
`[tool.ruff.lint]` section again. Ruff does not merge those with the
root, so `auth`, `postgrest`, `storage`, `realtime` and `functions`
skipped the root's `B` and `ANN2` rules. That hid a regression of the
`text_search` mutable default that #1887 had fixed.

This restores the shared config, adds more rule families, and tightens
pyrefly now that the minimum is Python 3.12.

## Config

- Every package `pyproject.toml` uses `[tool.ruff] extend =
"../../pyproject.toml"` instead of its own rule list.
- The root config brings back `PLE`, `PLW`, `PIE`, `LOG`, `FLY` and
`YTT` from #1887, and adds `ASYNC`, `C4`, `RSE`, `SIM`, `RET`, `PYI`,
`PT`, `TC`, `PERF` and `RUF`. The full `PT` and `RUF` families replace
`PT014` and `RUF100`. `RUF006` and `ASYNC` also cover SDK-2832.
- `TC` treats `pydantic.BaseModel` subclasses and standard and pydantic
dataclasses as runtime-evaluated. The imports their fields need stay at
runtime, so pydantic validation and `typing.get_type_hints` on them
still work.
- `pyrefly.toml` pins `python-version = "3.12"`. Before, pyrefly used
whatever interpreter the virtual environment had. It also promotes
`unreachable`, `division-by-zero`, `no-any-return-explicit` and
`untyped-namedtuple` to errors. All four were clean.

## Library fixes

- **postgrest:** `text_search` no longer uses a mutable `{}` default
(`B006`). `APIError` raised after a failed response validation chains
the `ValidationError` (`B904`).
- **realtime:** `MaxRetriesExceeded` chains the last connection error
(`B904`). `RealtimePresence` no longer overwrites its loop variable
(`PLW2901`). `__aexit__` uses `contextlib.suppress` (`SIM105`).
- **storage:** The missing-trailing-slash warning now points at the code
that creates the client (`B028`).
- **All clients:** `__enter__` and `__aenter__` return `Self` instead of
the concrete class, so subclasses get the right type (`PYI034`).
- Imports used only in annotations moved under `TYPE_CHECKING` (`TC`).
`__all__` lists are sorted (`RUF022`).
- `auth`'s `AMREntry.method` and `Factor.factor_type` keep `Literal[...]
| str` with `# noqa: PYI051`, because the literals are there for editor
completion.

## Test fixes

- **realtime:** Tests keep a reference to the tasks they start with
`asyncio.create_task` and await them (`RUF006`). Nested `async with`
blocks are merged (`SIM117`).
- **storage:** Removed the unused `delete_left_buckets` fixture, along
with the global bucket list and finalizer helpers that only it used
(`PT021`, `PLW0602`).
- Fixtures that only returned a value no longer `yield` (`PT022`). Their
return types now match what they return, which pyrefly checks.
- Parametrize names are tuples (`PT006`). `pytest.raises` and
`pytest.warns` calls set `match` (`PT011`, `PT030`, `RUF043`). The
duplicate `sanitize_param` case is removed (`PT014`).
- The auth sync tests were regenerated with `make auth.build-sync`.

## Testing

- `make ruff` and `make pyrefly` pass on all packages.
- `functions`, `utils`, `supabase`, `postgrest`, `realtime` and
`storage` test suites pass locally.
- `auth`: the local runs failed with connection errors to the auth
server on `localhost:9998`, so CI is the check for it.
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