-
-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: generic query builders #309
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #309 +/- ##
==========================================
- Coverage 91.56% 91.36% -0.20%
==========================================
Files 24 24
Lines 1197 1216 +19
==========================================
+ Hits 1096 1111 +15
- Misses 101 105 +4
☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM,
Thanks for putting this together
Just realised that the current solution doesn't type-check correctly when a = client.from_("entries").select("*").execute()
reveal_type(a.data) # Type of a.data is List[Dict[str, Any]]
b = client.from_("entries").select("*").single().execute()
reveal_type(b.data) # Type of b.data is List[Dict[str, Any]]
# but it should be just Dict[str, Any] There are no errors at runtime, but this will be annoying for users who use static type-checkers. Pushing a fix now. |
This makes sure the return types of rpc() and other query methods are correct. See https://gist.github.com/anand2312/93d3abf401335fd3310d9e30112303bf for an explanation.
it would be nice if we could do this python/mypy#9319 (comment) |
This fixes the type-checker error raised while accessing RequestBuilder[T].__origin__
@olirice The error for |
Fixes #200
This PR makes all the request builders and the APIResponse classes generic;
This fixes the issue by using
APIResponse[Any]
as the return type for rpc calls, while usingAPIResponse[list[dict[str, Any]]
for other queries.This also opens us up to (in the future) allowing users to pass in their own pydantic models to the query, so that the response is well-typed.
Marked as draft to write more tests