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

Commit b5324a5

Browse files
committed
fix: remove reliance on SyncClient and use Client directly from httpx
fix: add deprecation warnings for SyncClient test: update to use Client instead of SyncClient
1 parent a3fda4a commit b5324a5

File tree

8 files changed

+35
-16
lines changed

8 files changed

+35
-16
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ build_sync:
1919
poetry run unasync supabase_functions tests
2020
sed -i '0,/SyncMock, /{s/SyncMock, //}' tests/_sync/test_function_client.py
2121
sed -i 's/SyncMock/Mock/g' tests/_sync/test_function_client.py
22+
sed -i 's/SyncClient/Client/g' supabase_functions/_sync/functions_client.py tests/_sync/test_function_client.py
2223

2324

2425
rename_project: rename_package_dir rename_package

supabase_functions/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
from __future__ import annotations
22

3-
from typing import Literal, Optional, Union, overload
3+
from typing import Literal, Union, overload
44

55
from ._async.functions_client import AsyncFunctionsClient
66
from ._sync.functions_client import SyncFunctionsClient
77
from .utils import FunctionRegion
88

9-
__all__ = ["create_client"]
9+
__all__ = [
10+
"create_client",
11+
"FunctionRegion",
12+
"AsyncFunctionsClient",
13+
"SyncFunctionsClient",
14+
]
1015

1116

1217
@overload

supabase_functions/_async/functions_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from typing import Any, Dict, Literal, Optional, Union
22
from warnings import warn
33

4-
from httpx import HTTPError, Response
4+
from httpx import AsyncClient, HTTPError, Response
55

66
from ..errors import FunctionsHttpError, FunctionsRelayError
77
from ..utils import (
8-
AsyncClient,
98
FunctionRegion,
109
is_http_url,
1110
is_valid_jwt,

supabase_functions/_sync/functions_client.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
from typing import Any, Dict, Literal, Optional, Union
22
from warnings import warn
33

4-
from httpx import HTTPError, Response
4+
from httpx import Client, HTTPError, Response
55

66
from ..errors import FunctionsHttpError, FunctionsRelayError
77
from ..utils import (
88
FunctionRegion,
9-
SyncClient,
109
is_http_url,
1110
is_valid_jwt,
1211
is_valid_str_arg,
@@ -22,7 +21,7 @@ def __init__(
2221
timeout: Optional[int] = None,
2322
verify: Optional[bool] = None,
2423
proxy: Optional[str] = None,
25-
http_client: Optional[SyncClient] = None,
24+
http_client: Optional[Client] = None,
2625
):
2726
if not is_http_url(url):
2827
raise ValueError("url must be a valid HTTP URL string")
@@ -59,7 +58,7 @@ def __init__(
5958
http_client.headers.update({**self.headers})
6059
self._client = http_client
6160
else:
62-
self._client = SyncClient(
61+
self._client = Client(
6362
base_url=self.url,
6463
headers=self.headers,
6564
verify=self.verify,

supabase_functions/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import re
22
import sys
33
from urllib.parse import urlparse
4+
from warnings import warn
45

56
from httpx import AsyncClient as AsyncClient # noqa: F401
67
from httpx import Client as BaseClient
@@ -34,7 +35,21 @@ class FunctionRegion(StrEnum):
3435

3536

3637
class SyncClient(BaseClient):
38+
def __init__(self, *args, **kwargs):
39+
warn(
40+
"The 'SyncClient' class is deprecated. Please use `Client` from the httpx package instead.",
41+
DeprecationWarning,
42+
stacklevel=2,
43+
)
44+
45+
super().__init__(*args, **kwargs)
46+
3747
def aclose(self) -> None:
48+
warn(
49+
"The 'aclose' method is deprecated. Please use `close` method from `Client` in the httpx package instead.",
50+
DeprecationWarning,
51+
stacklevel=2,
52+
)
3853
self.close()
3954

4055

tests/_async/test_function_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from unittest.mock import AsyncMock, Mock, patch
22

33
import pytest
4-
from httpx import HTTPError, Response, Timeout
4+
from httpx import AsyncClient, HTTPError, Response, Timeout
55

66
# Import the class to test
77
from supabase_functions import AsyncFunctionsClient
88
from supabase_functions.errors import FunctionsHttpError, FunctionsRelayError
9-
from supabase_functions.utils import AsyncClient, FunctionRegion
9+
from supabase_functions.utils import FunctionRegion
1010
from supabase_functions.version import __version__
1111

1212

tests/_sync/test_function_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from unittest.mock import Mock, patch
22

33
import pytest
4-
from httpx import HTTPError, Response, Timeout
4+
from httpx import Client, HTTPError, Response, Timeout
55

66
# Import the class to test
77
from supabase_functions import SyncFunctionsClient
88
from supabase_functions.errors import FunctionsHttpError, FunctionsRelayError
9-
from supabase_functions.utils import FunctionRegion, SyncClient
9+
from supabase_functions.utils import FunctionRegion
1010
from supabase_functions.version import __version__
1111

1212

@@ -186,7 +186,7 @@ def test_invoke_with_json_body(client: SyncFunctionsClient):
186186
def test_init_with_httpx_client():
187187
# Create a custom httpx client with specific options
188188
headers = {"x-user-agent": "my-app/0.0.1"}
189-
custom_client = SyncClient(
189+
custom_client = Client(
190190
timeout=Timeout(30), follow_redirects=True, max_redirects=5, headers=headers
191191
)
192192

tests/test_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def test_type_hints():
4242

4343
hints = get_type_hints(create_client)
4444

45-
assert hints["url"] == str
45+
assert hints["url"] is str
4646
assert hints["headers"] == dict[str, str]
47-
assert hints["is_async"] == bool
48-
assert hints["verify"] == bool
47+
assert hints["is_async"] is bool
48+
assert hints["verify"] is bool
4949
assert hints["return"] == Union[AsyncFunctionsClient, SyncFunctionsClient]

0 commit comments

Comments
 (0)