Skip to content

Commit d688a1f

Browse files
authored
chore(functions): add mypy checks to functions (#1218)
1 parent f88cb25 commit d688a1f

File tree

7 files changed

+43
-16
lines changed

7 files changed

+43
-16
lines changed

src/functions/Makefile

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
1-
tests: pytest
1+
help::
2+
@echo "Available commands"
3+
@echo " help -- (default) print this message"
4+
5+
tests: mypy pytest
6+
help::
7+
@echo " tests -- run all tests for supabase_functions package"
28

39
pytest:
410
uv run --package supabase_functions pytest --cov=./ --cov-report=xml --cov-report=html -vv
11+
help::
12+
@echo " pytest -- run pytest on supabase_functions package"
13+
14+
mypy:
15+
uv run --package supabase_functions mypy src/supabase_functions tests
16+
help::
17+
@echo " mypy -- run mypy on supabase_functions package"
518

619
unasync:
720
uv run --package supabase_functions run-unasync.py
21+
help::
22+
@echo " unasync -- invoke run-unasync.py helper"
823

924
build-sync: unasync
1025
sed -i '0,/SyncMock, /{s/SyncMock, //}' tests/_sync/test_function_client.py
1126
sed -i 's/SyncMock/Mock/g' tests/_sync/test_function_client.py
1227
sed -i 's/SyncClient/Client/g' src/supabase_functions/_sync/functions_client.py tests/_sync/test_function_client.py
28+
help::
29+
@echo " build-sync -- generate _sync from _async implementation"
1330

1431
clean:
1532
rm -rf htmlcov .pytest_cache .mypy_cache .ruff_cache
1633
rm -f .coverage coverage.xml
34+
help::
35+
@echo " clean -- clean intermediary files"
1736

1837
build:
1938
uv build --package supabase_functions
39+
help::
40+
@echo " build -- invoke uv build on supabase_functions package"

src/functions/pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ tests = [
3232
lints = [
3333
"unasync>=0.6.0",
3434
"ruff >=0.12.1",
35-
"pre-commit >=3.4,<5.0"
35+
"pre-commit >=3.4,<5.0",
36+
"python-lsp-server (>=1.12.2,<2.0.0)",
37+
"pylsp-mypy (>=0.7.0,<0.8.0)",
38+
"python-lsp-ruff (>=2.2.2,<3.0.0)",
3639
]
3740
dev = [{ include-group = "lints" }, {include-group = "tests" }]
3841

src/functions/run-unasync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import unasync
22
from pathlib import Path
33

4-
paths = Path("src/functions").glob("**/*.py")
4+
paths = Path("src/supabase_functions").glob("**/*.py")
55
tests = Path("tests").glob("**/*.py")
66

77
rules = (unasync._DEFAULT_RULE,)

src/functions/src/supabase_functions/_async/functions_client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ async def _request(
7474
headers: Optional[Dict[str, str]] = None,
7575
json: Optional[Dict[Any, Any]] = None,
7676
) -> Response:
77-
user_data = {"data": json} if isinstance(json, str) else {"json": json}
78-
response = await self._client.request(method, url, **user_data, headers=headers)
79-
77+
response = (
78+
await self._client.request(method, url, data=json, headers=headers)
79+
if isinstance(json, str)
80+
else await self._client.request(method, url, json=json, headers=headers)
81+
)
8082
try:
8183
response.raise_for_status()
8284
except HTTPError as exc:

src/functions/src/supabase_functions/_sync/functions_client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ def _request(
7474
headers: Optional[Dict[str, str]] = None,
7575
json: Optional[Dict[Any, Any]] = None,
7676
) -> Response:
77-
user_data = {"data": json} if isinstance(json, str) else {"json": json}
78-
response = self._client.request(method, url, **user_data, headers=headers)
79-
77+
response = (
78+
self._client.request(method, url, data=json, headers=headers)
79+
if isinstance(json, str)
80+
else self._client.request(method, url, json=json, headers=headers)
81+
)
8082
try:
8183
response.raise_for_status()
8284
except HTTPError as exc:

src/functions/src/supabase_functions/py.typed

Whitespace-only changes.

src/functions/tests/test_errors.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ def test_error_initialization(
2222
error_class: Type[FunctionsError], expected_name: str, expected_status: int
2323
):
2424
test_message = "Test error message"
25-
26-
if error_class is FunctionsError:
25+
if issubclass(error_class, (FunctionsHttpError, FunctionsRelayError)):
26+
error: FunctionsError = error_class(test_message)
27+
elif error_class is FunctionsError:
2728
error = error_class(test_message, expected_name, expected_status)
28-
else:
29-
error = error_class(test_message)
3029

3130
assert str(error) == test_message
3231
assert error.message == test_message
@@ -48,10 +47,10 @@ def test_error_to_dict(
4847
):
4948
test_message = "Test error message"
5049

51-
if error_class is FunctionsError:
50+
if issubclass(error_class, (FunctionsHttpError, FunctionsRelayError)):
51+
error: FunctionsError = error_class(test_message)
52+
elif error_class is FunctionsError:
5253
error = error_class(test_message, expected_name, expected_status)
53-
else:
54-
error = error_class(test_message)
5554

5655
error_dict = error.to_dict()
5756

0 commit comments

Comments
 (0)