Fix: geoalchemy2.functions type stubs #481
Merged
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.
Description
I made a mistake when writing the function stub generator. I should have familiarised myself with geoalchemy2 first (I have never used it before, I contributed the types to improve type checking coverage in a codebase that I work with).
The dynamic 'functions' in the
geoalchemy2.functions
module are only markers to be used to construct SQL queries and do no computation themselves and thus the type hints were incorrect. I knew they served the SQL construction purpose but for some reason I was under the impression that they could also be used as regular functions egbut this is not the case.
I took a look at how functions are type hinted in SQLAlchemy, for example the SQLAlchemy documentation explains how to create a custom generic function:
So the geoalchemy functions should look like this.
There is a more specific way these can be typed, quoting the latest SQLAlchemy source code:
but this is not available in SQLAlchemy 1.4 which GeoAlchemy2 has as the minimum version and I also wasn't sure what to put as the value for
GenericFunction[T]
Checklist
This pull request is:
Fixes: #<issue number>
in the description if it solves an existing issue(which must include a complete example of the issue).
main
branch and pass with the provided fix.Fixes: #<issue number>
in the description if it solves an existing issue(which must include a complete example of the feature).