Skip to content

Conversation

@o-santi
Copy link
Contributor

@o-santi o-santi commented Nov 4, 2025

What kind of change does this PR introduce?

Make mypy supabase pass with no errors in a weak ruleset. Also enforce the same ruff linting rules as auth, in order to catch missing annotations and unused variables/imports (currently, only auth has these, I still intend to enforce this workspace wide in the future).

Additional context

There was a small bug related to SyncGoTrueAPI.__exit__ I fixed in the middle of this PR. Specifically, the AsyncGoTrueAPI has a close method that calls self.httpx_client.aclose() internally, but that method does not exist on the sync version, so instead of patching in on the build-sync command, it instead created a custom SyncClient class specific for auth, which added an aclose method.

However, supabase does not care to use this SyncClient class when an httpx_client argument is passed in (which is a type error), which means that if the __exit__ method is called, it throws an error. Eg. if a user used the sync version with a custom httpx_client and uses a with block, it throws an error:

from supabase import create_client, ClientOptions
from httpx import Client


def test():
    client = create_client(
        supabase_url="http://127.0.0.1:54321/",
        supabase_key="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYzNTAwODQ4NywiZXhwIjoxOTUwNTg0NDg3fQ.l8IgkO7TQokGSc9OJoobXIVXsOXkilXl4Ak6SCX5qI8",
        options=ClientOptions(httpx_client = Client())
    )
    with client.auth as auth:
        print(auth._http_client)

if __name__ == "__main__":
    test()

throws:

<httpx.Client object at 0x7fc5649bced0>
Traceback (most recent call last):
  File "/home/leonardo/sp/supabase-py/test.py", line 19, in <module>
    asyncio.run(test())
  File "/nix/store/9bzwn5qvvgmczx0ilxacisf7cqiqlz9j-python3-3.11.13/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/nix/store/9bzwn5qvvgmczx0ilxacisf7cqiqlz9j-python3-3.11.13/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/9bzwn5qvvgmczx0ilxacisf7cqiqlz9j-python3-3.11.13/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/leonardo/sp/supabase-py/test.py", line 13, in test
    with client.auth as auth:
  File "/home/leonardo/sp/supabase-py/src/auth/src/supabase_auth/_sync/gotrue_base_api.py", line 39, in __exit__
    self.close()
  File "/home/leonardo/sp/supabase-py/src/auth/src/supabase_auth/_sync/gotrue_base_api.py", line 42, in close
    self._http_client.aclose()
    ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Client' object has no attribute 'aclose'. Did you mean: 'close'?

Goes to show the importance of type checking your code! The fix for this was to remove this class and manually patch aclose to translate to close in auth/scripts/run-async.py.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 19077887938

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 158 unchanged lines in 10 files lost coverage.
  • Overall coverage increased (+0.07%) to 92.641%

Files with Coverage Reduction New Missed Lines %
src/supabase/_sync/auth_client.py 1 87.5%
src/supabase/_async/auth_client.py 1 87.5%
src/supabase_auth/_async/gotrue_base_api.py 3 91.67%
src/supabase_auth/_sync/gotrue_base_api.py 3 91.67%
src/supabase/_async/client.py 6 95.31%
src/supabase/_sync/client.py 6 95.24%
src/supabase_auth/_sync/gotrue_admin_api.py 9 79.8%
src/supabase_auth/_async/gotrue_admin_api.py 9 79.8%
src/supabase_auth/_async/gotrue_client.py 58 73.69%
src/supabase_auth/_sync/gotrue_client.py 62 72.82%
Totals Coverage Status
Change from base Build 19043813501: 0.07%
Covered Lines: 8724
Relevant Lines: 9417

💛 - Coveralls

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.

4 participants