Skip to content
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

Fix: geoalchemy2.functions type stubs #481

Merged
merged 2 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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