Skip to content
Open
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
16 changes: 14 additions & 2 deletions src/datastar_py/django.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from __future__ import annotations

from collections.abc import Awaitable, Callable, Mapping
from collections.abc import Awaitable, Callable, Coroutine, Mapping
from functools import wraps
from inspect import isasyncgenfunction, isawaitable, iscoroutinefunction
from typing import Any, ParamSpec
from typing import Any, ParamSpec, overload

from django.http import HttpRequest
from django.http import StreamingHttpResponse as _StreamingHttpResponse
Expand Down Expand Up @@ -44,6 +44,18 @@ def __init__(
P = ParamSpec("P")


@overload
def datastar_response(
func: Callable[P, Coroutine[Any, Any, DatastarEvents]],
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the Coroutine here correct? Doesn't that eliminate async generators, which should be valid?

@datastar_response
async def async_gen():
    yield SSE.patch_elements('<div id="aoeu"></div>')

) -> Callable[P, Coroutine[Any, Any, DatastarResponse]]: ...


@overload
def datastar_response(
func: Callable[P, DatastarEvents],
) -> Callable[P, DatastarResponse]: ...


def datastar_response(
func: Callable[P, Awaitable[DatastarEvents] | DatastarEvents],
) -> Callable[P, Awaitable[DatastarResponse] | DatastarResponse]:
Expand Down