Skip to content

Commit 82f60b9

Browse files
authored
feat: mypy postgrest (#1231)
1 parent 6be6c0c commit 82f60b9

File tree

13 files changed

+296
-296
lines changed

13 files changed

+296
-296
lines changed

src/postgrest/Makefile

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,47 @@
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 postgrest package"
28

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

619
start-infra:
720
cd infra &&\
821
docker compose down &&\
922
docker compose up -d
1023
sleep 2
24+
help::
25+
@echo " stop-infra -- start containers for tests"
26+
27+
stop-infra:
28+
cd infra &&\
29+
docker compose down --remove-orphans
30+
help::
31+
@echo " stop-infra -- stop containers for tests"
1132

1233
clean-infra:
1334
cd infra &&\
1435
docker compose down --remove-orphans &&\
1536
docker system prune -a --volumes -f
16-
17-
stop-infra:
18-
cd infra &&\
19-
docker compose down --remove-orphans
37+
help::
38+
@echo " clean-infra -- delete all stored information about the containers"
2039

2140
clean:
2241
rm -rf htmlcov .pytest_cache .mypy_cache .ruff_cache
2342
rm -f .coverage coverage.xml
43+
help::
44+
@echo " clean -- clean intermediary files generated by tests"
2445

2546
unasync:
2647
uv run --package postgrest run-unasync.py
@@ -33,6 +54,10 @@ build-sync: unasync
3354
sed -i 's/SyncHTTPTransport/HTTPTransport/g' tests/_sync/**.py
3455
sed -i 's/SyncClient/Client/g' src/postgrest/_sync/**.py tests/_sync/**.py
3556
sed -i 's/self\.session\.aclose/self\.session\.close/g' src/postgrest/_sync/client.py
57+
help::
58+
@echo " build-sync -- generate _sync from _async implementation"
3659

3760
build:
3861
uv build --package postgrest
62+
help::
63+
@echo " build -- invoke uv build on storage3 package"

src/postgrest/pyproject.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ test = [
4343
lints = [
4444
"pre-commit >=4.2.0",
4545
"ruff >=0.12.1",
46+
"python-lsp-server (>=1.12.2,<2.0.0)",
47+
"pylsp-mypy (>=0.7.0,<0.8.0)",
48+
"python-lsp-ruff (>=2.2.2,<3.0.0)",
4649
]
4750
docs = [
4851
"sphinx >=7.1.2",
@@ -84,3 +87,15 @@ filterwarnings = [
8487
[build-system]
8588
requires = ["uv_build>=0.8.3,<0.9.0"]
8689
build-backend = "uv_build"
90+
91+
[tool.mypy]
92+
python_version = "3.9"
93+
check_untyped_defs = true
94+
allow_redefinition = true
95+
follow_untyped_imports = true # for deprecation module that does not have stubs
96+
97+
no_warn_no_return = true
98+
warn_return_any = true
99+
warn_unused_configs = true
100+
warn_redundant_casts = true
101+
warn_unused_ignores = true

src/postgrest/run-unasync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import unasync
44

5-
paths = Path("src/supabase").glob("**/*.py")
5+
paths = Path("src/postgrest").glob("**/*.py")
66
tests = Path("tests").glob("**/*.py")
77

88
rules = (unasync._DEFAULT_RULE,)

src/postgrest/src/postgrest/_async/client.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
from ..version import __version__
1616
from .request_builder import AsyncRequestBuilder, AsyncRPCFilterRequestBuilder
1717

18-
_TableT = Dict[str, Any]
19-
2018

2119
class AsyncPostgrestClient(BasePostgrestClient):
2220
"""PostgREST client."""
@@ -72,7 +70,7 @@ def __init__(
7270
proxy=proxy,
7371
http_client=http_client,
7472
)
75-
self.session = cast(AsyncClient, self.session)
73+
self.session: AsyncClient = self.session
7674

7775
def create_session(
7876
self,
@@ -122,17 +120,17 @@ async def aclose(self) -> None:
122120
"""Close the underlying HTTP connections."""
123121
await self.session.aclose()
124122

125-
def from_(self, table: str) -> AsyncRequestBuilder[_TableT]:
123+
def from_(self, table: str) -> AsyncRequestBuilder:
126124
"""Perform a table operation.
127125
128126
Args:
129127
table: The name of the table
130128
Returns:
131129
:class:`AsyncRequestBuilder`
132130
"""
133-
return AsyncRequestBuilder[_TableT](self.session, f"/{table}")
131+
return AsyncRequestBuilder(self.session, f"/{table}")
134132

135-
def table(self, table: str) -> AsyncRequestBuilder[_TableT]:
133+
def table(self, table: str) -> AsyncRequestBuilder:
136134
"""Alias to :meth:`from_`."""
137135
return self.from_(table)
138136

@@ -148,7 +146,7 @@ def rpc(
148146
count: Optional[CountMethod] = None,
149147
head: bool = False,
150148
get: bool = False,
151-
) -> AsyncRPCFilterRequestBuilder[Any]:
149+
) -> AsyncRPCFilterRequestBuilder:
152150
"""Perform a stored procedure call.
153151
154152
Args:
@@ -175,7 +173,7 @@ def rpc(
175173
headers = Headers({"Prefer": f"count={count}"}) if count else Headers()
176174

177175
if method in ("HEAD", "GET"):
178-
return AsyncRPCFilterRequestBuilder[Any](
176+
return AsyncRPCFilterRequestBuilder(
179177
self.session,
180178
f"/rpc/{func}",
181179
method,
@@ -184,6 +182,6 @@ def rpc(
184182
json={},
185183
)
186184
# the params here are params to be sent to the RPC and not the queryparams!
187-
return AsyncRPCFilterRequestBuilder[Any](
185+
return AsyncRPCFilterRequestBuilder(
188186
self.session, f"/rpc/{func}", method, headers, QueryParams(), json=params
189187
)

0 commit comments

Comments
 (0)