Skip to content

Commit

Permalink
Fix: geoalchemy2.functions type stubs (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbway authored Oct 21, 2023
1 parent 14aff4c commit ee5b5ad
Show file tree
Hide file tree
Showing 3 changed files with 630 additions and 1,858 deletions.
17 changes: 5 additions & 12 deletions geoalchemy2/_functions_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def _generate_stubs() -> str:

header = '''\
# this file is automatically generated
from typing import Any
from typing import List
from sqlalchemy.sql import functions
Expand All @@ -67,27 +66,21 @@ def _from_objects(self) -> List[bool]: ... # type: ignore[override]
stub_file_parts = [header]

functions = _FUNCTIONS.copy()
functions.insert(0, ("ST_AsGeoJSON", str, ST_AsGeoJSON.__doc__))
functions.insert(0, ("ST_AsGeoJSON", None, ST_AsGeoJSON.__doc__))

for name, type_, doc_parts in functions:
doc = _replace_indent(_get_docstring(name, doc_parts, type_), " ")

if type_ is None:
type_str = "Any"
elif type_.__module__ == "builtins":
type_str = type_.__name__
type_str = ""
else:
type_str = f"{type_.__module__}.{type_.__name__}"
type_str = f"\n\n type = {type_.__module__}.{type_.__name__}()"

signature = f'''\
class _{name}(functions.GenericFunction):
class {name}(GenericFunction):
"""
{doc}
"""
def __call__(self, *args: Any, **kwargs: Any) -> {type_str}: ...
{name}: _{name}
"""{type_str}
'''
stub_file_parts.append(signature)

Expand Down
Loading

0 comments on commit ee5b5ad

Please sign in to comment.