Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Fix type definitions enough for mypy with a weak ruleset to accept them.
What is the current behavior?
mypy
is not happy.What is the new behavior?
mypy
happy.Also improved
src/postgrest/Makefile
and fixed some stuff likemake build-sync
that was broken.Additional context
I had to remove all generics from the response type, and from all the builders that used it, as its usage is completely wrong. I believe the idea for it is based on Swift, where the types used can be used to monomorphize the implementation to one that validates form JSON to the type itself, which is great.
Sadly, not only the current python implementation did not do that, but python as a whole is unable to leverage any smart implementation, as the types cannot contribute with computational content, and thus we cannot use the type declared at the class to decode the payload.
Moreover, in the actual implementation, the only thing we did was decode the response as JSON, by way of
response.json()
, which returnsAny
type. This means that any type was passable in the generic, and the type checker wouldn't complain, making the types unsound and the type checker useless. This also means that this whole change is non breaking, as any user relying on these generics is by definition incorrect.The way to fix this was to downgrade the generic types to a less informative
JSON
type, which is just a way of saying that the best we can do is ensure the data is JSON. We can think of better ways to improve it further by usingpydantic
classes, but I believe those would require breaking changes.