Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.

Conversation

@o-santi
Copy link
Contributor

@o-santi o-santi commented Jul 9, 2025

What kind of change does this PR introduce?

Improves typing definitions enough for mypy with a weak rule set to accept them. This is mostly an initial patch set to ease reviewing, as there are many things to improve still - mainly, remove Any usage in favor of generics, and improve the types of payloads with actual pydantic-based validation, with the ultimate goal of making the code type check with strict = true.

It also adds a new step to enforce mypy ./realtime in CI from now on.

What is the current behavior?

No type checking at all.

What is the new behavior?

$ mypy ./realtime
Success: no issues found in 17 source files

Additional context

This should contain no breaking changes, just some rewiring of internal plumbing. The only real change I made is removing the AsyncRealtimeClient.summary method, which was broken as it used a non existant channel.listeners property.

o-santi added 30 commits July 1, 2025 13:04
introduce flake.nix configuration leveraging the already existing
information in pyproject.toml, by using pyproject.nix to parse it and
generate the correct derivation. this way, any updates to
pyproject.toml should automatically be reflected in the flake
configuration, with low additional maintaining overhead required.

the only time when this may come as a problem is due to dependabot
constantly upgrading the packages to versions that do not exist yet in
nixpkgs. it may be required to force dependabot to also update the
nixpkgs version declared in the flake for it to not also break (or at
least to upgrade less often)
… pre-commit

by adding `dependency-groups`, `pyproject.nix` can now parse the
dependency groups and add these to the project, by passing `groups =
["dev"]` when calling the renderer.

special care was needed in order to expose `ruff` and `pre-commit` to
the toplevel of the environment. by default, it will treat them as
python dependencies and hide them in the python wrapper. by using
`groupBy`, we split the dependency list in "python" dependencies and
top level ones, such that they can be exposed.

sadly, these toplevel packages are not exposed in `python.pkgs` so we
must manually override them in a case by case basis.
ensure that `nix develop` works on CI
…p action

do not rely on poetry to run tests, we'd like to not rely on it from
within the nix environment
use manual `supabase start` command instead
for some reason, `supabase start` does not seem to work on
`macos-latest` host in CI
it seems that pyright is better and faster than mypy in most if not
all cases, and the only reason I wasn't using it before is because it
was not working with eglot's default config.
this makes it available to all users, preparing for including it into
the standard CI later on
there's still a lot of issues that I intend to improve upon. this is
just an initial set of changes to ensure that `mypy` doesn't
complain. we should further strengthen the mypy checking
rules (currently there are a lot of `Any`s in the code) as the code improves.
@grdsdev grdsdev requested a review from Copilot July 9, 2025 18:27
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Improves type safety by refining typing definitions across the realtime module and integrates MyPy into CI.

  • Updated typing annotations (e.g., Mapping, TypedDict, callback generics) and reduced Any usage.
  • Converted Message to a Pydantic BaseModel and removed the broken summary method.
  • Added MyPy configuration and CI steps for automated type checking.

Reviewed Changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
realtime/types.py Refined enum type hint, updated callback and TypedDict definitions
realtime/message.py Switched Message to Pydantic BaseModel and adjusted payload type
realtime/exceptions.py Broadened error message parameter type
realtime/_async/push.py Switched to Pydantic Message, updated payload types and hook logic
realtime/_async/presence.py Replaced callback dict with individual attributes and updated hook flows
realtime/_async/client.py Fixed send/receive for Message, updated connection typing and logging
realtime/_async/channel.py Updated callback signatures, replaced raw dicts with Message, removed summary
pyproject.toml Added pydantic dependency and MyPy settings
.github/workflows/ci.yml Added MyPy type-check steps using Poetry and Nix
Comments suppressed due to low confidence (3)

realtime/_async/channel.py:318

  • [nitpick] Parameter type shadows the built-in type and filter shadows the built-in filter. Consider renaming to more descriptive names like event_type and filter_args to improve readability and avoid confusion.
    def _on(

.github/workflows/ci.yml:39

  • [nitpick] There are duplicate Type check steps in the CI workflow (one using Poetry and one using Nix). Consider consolidating them or giving each a distinct name to clarify their purpose.
      - name: Type check

realtime/_async/channel.py:265

  • Changed the payload for the phx_close event from the original "leave" string to an empty dict, which may break consumers expecting a termination reason. Consider restoring the original payload or updating callers accordingly.
            self._trigger(ChannelEvents.close, {})

@dataclass
class Message:

class Message(BaseModel):
Copy link

Copilot AI Jul 9, 2025

Choose a reason for hiding this comment

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

Removal of the __hash__ method makes Message instances unhashable; if these objects need to be used in sets or dict keys, consider reintroducing a custom __hash__ implementation or documenting this change.

Copilot uses AI. Check for mistakes.
@coveralls
Copy link

coveralls commented Jul 10, 2025

Pull Request Test Coverage Report for Build 16199329439

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 110 unchanged lines in 6 files lost coverage.
  • Overall coverage decreased (-0.01%) to 81.078%

Files with Coverage Reduction New Missed Lines %
types.py 1 98.91%
exceptions.py 2 63.64%
_async/push.py 12 85.37%
_async/presence.py 18 80.37%
_async/client.py 29 74.21%
_async/channel.py 48 75.11%
Totals Coverage Status
Change from base Build 16148084255: -0.01%
Covered Lines: 647
Relevant Lines: 798

💛 - Coveralls

@o-santi o-santi requested a review from grdsdev July 10, 2025 15:52
@o-santi o-santi self-assigned this Jul 10, 2025
@o-santi o-santi requested a review from silentworks July 10, 2025 15:55
@o-santi o-santi merged commit 513ae3a into supabase:main Jul 10, 2025
18 of 19 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants