Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- synchronize

jobs:
Linters:
Tests:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand Down
10 changes: 6 additions & 4 deletions fasthx/core_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def hx(
*,
no_data: bool = False,
render_error: RenderFunction[Exception] | None = None,
) -> Callable[[MaybeAsyncFunc[P, T]], Callable[P, Coroutine[None, None, T | Response]]]:
) -> Callable[[MaybeAsyncFunc[P, T | Response]], Callable[P, Coroutine[None, None, T | Response]]]:
"""
Decorator that converts a FastAPI route's return value into HTML if the request was
an HTMX one.
Expand All @@ -31,7 +31,9 @@ def hx(
The rendered HTML for HTMX requests, otherwise the route's unchanged return value.
"""

def decorator(func: MaybeAsyncFunc[P, T]) -> Callable[P, Coroutine[None, None, T | Response]]:
def decorator(
func: MaybeAsyncFunc[P, T | Response],
) -> Callable[P, Coroutine[None, None, T | Response]]:
@wraps(func)
async def wrapper(
__hx_request: DependsHXRequest, *args: P.args, **kwargs: P.kwargs
Expand Down Expand Up @@ -84,7 +86,7 @@ def page(
render: RenderFunction[T],
*,
render_error: RenderFunction[Exception] | None = None,
) -> Callable[[MaybeAsyncFunc[P, T]], Callable[P, Coroutine[None, None, Response]]]:
) -> Callable[[MaybeAsyncFunc[P, T | Response]], Callable[P, Coroutine[None, None, Response]]]:
"""
Decorator that converts a FastAPI route's return value into HTML.

Expand All @@ -94,7 +96,7 @@ def page(
If not `None`, it is expected to raise an error if the exception can not be rendered.
"""

def decorator(func: MaybeAsyncFunc[P, T]) -> Callable[P, Coroutine[None, None, Response]]:
def decorator(func: MaybeAsyncFunc[P, T | Response]) -> Callable[P, Coroutine[None, None, Response]]:
@wraps(func)
async def wrapper(
__page_request: DependsPageRequest, *args: P.args, **kwargs: P.kwargs
Expand Down
4 changes: 2 additions & 2 deletions fasthx/htmy.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def hx(
*,
error_component_selector: HTMYComponentSelector[Exception] | None = None,
no_data: bool = False,
) -> Callable[[MaybeAsyncFunc[P, T]], Callable[P, Coroutine[None, None, T | Response]]]:
) -> Callable[[MaybeAsyncFunc[P, T | Response]], Callable[P, Coroutine[None, None, T | Response]]]:
"""
Decorator for rendering the route's result if the request was an HTMX one.

Expand All @@ -163,7 +163,7 @@ def page(
component_selector: HTMYComponentSelector[T] | None = None,
*,
error_component_selector: HTMYComponentSelector[Exception] | None = None,
) -> Callable[[MaybeAsyncFunc[P, T]], Callable[P, Coroutine[None, None, T | Response]]]:
) -> Callable[[MaybeAsyncFunc[P, T | Response]], Callable[P, Coroutine[None, None, T | Response]]]:
"""
Decorator for rendering a route's result.

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "fasthx"
version = "3.0.0"
version = "3.0.1"
description = "FastAPI server-side rendering with built-in HTMX support."
authors = ["Peter Volf <[email protected]>"]
readme = "README.md"
Expand Down
4 changes: 3 additions & 1 deletion tests/test_htmy.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def index() -> list[User]:

@app.get("/htmx-or-data")
@htmy.hx(UserList)
def htmx_or_data(response: Response) -> list[User]:
def htmx_or_data(
response: Response,
) -> list[User]:
Comment on lines +41 to +43
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Minor formatting inconsistency.

The single parameter is now on its own line with a trailing comma, which differs from the style used for other single-parameter functions in this file (e.g., line 103). While the trailing comma is good practice for future-proofing, the inline style is more common for single parameters.

Note: The past review comments suggesting | Response in the return type and response_model=None in the decorator appear to be outdated and don't apply to the current code state.

🤖 Prompt for AI Agents
In tests/test_htmy.py around lines 41 to 43, the function signature for
htmx_or_data places the single parameter on its own line with a trailing comma
which is inconsistent with other single-parameter functions in this file; change
the signature to a single-line style like def htmx_or_data(response: Response)
-> list[User]: to match existing style (remove the extra line break and trailing
comma) while keeping the same parameter type and return annotation.

response.headers["test-header"] = "exists"
return users

Expand Down