Skip to content

Conversation

@volfpeter
Copy link
Owner

@volfpeter volfpeter commented Oct 12, 2025

This is only relevant for the htmy integration and the core decorators, because with Jinja the type information is not relevant (already Any).

Summary by CodeRabbit

  • New Features
    • Improved typing for HTMX decorators: handlers can now return data or a Response without type-checker warnings. No runtime behavior changes.
  • Tests
    • Minor formatting adjustment in a test function signature; behavior unchanged.
  • Chores
    • Renamed CI job from “Linters” to “Tests” for clarity.
    • Bumped package version to 3.0.1.

@coderabbitai
Copy link

coderabbitai bot commented Oct 12, 2025

Walkthrough

Type annotations expanded to allow decorators hx/page to accept functions returning either T or Response in both core_decorators and HTMY. No runtime logic changes. Tests receive minor formatting. Package version bumped to 3.0.1. CI workflow job renamed from “Linters” to “Tests”.

Changes

Cohort / File(s) Summary of Changes
Decorator typing updates
fasthx/core_decorators.py
Broadened type signatures: hx/page now accept MaybeAsyncFunc returning T or Response; inner decorator parameters updated accordingly. No runtime behavior changes.
HTMY typing updates
fasthx/htmy.py
Adjusted HTMY.hx/page input types to MaybeAsyncFunc[P, T | Response]; output annotations remain consistent. No logic changes.
Tests formatting
tests/test_htmy.py
Minor signature formatting (line break/trailing comma) without behavior change.
Project metadata
pyproject.toml
Version bump from 3.0.0 to 3.0.1.
CI workflow
.github/workflows/tests.yml
Job name changed from “Linters” to “Tests”.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title “Allow Response in route type hints” concisely captures the primary change of extending the core and HTMX decorator type signatures to permit returning a Response. It is specific and clear, directly reflecting the modifications to the decorator type hints without extraneous detail.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/allow-Response-in-route-type-hints

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 7b87cb4 and 17fbdcf.

📒 Files selected for processing (5)
  • fasthx/core_decorators.py (4 hunks)
  • fasthx/htmy.py (2 hunks)
  • pyproject.toml (1 hunks)
  • tests/test_core_decorators.py (2 hunks)
  • tests/test_htmy.py (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Tests
tests/test_htmy.py

[error] 34-34: FastAPIError: Invalid args for response field! Hint: check that {type_} is a valid Pydantic field type.

🔇 Additional comments (9)
pyproject.toml (1)

3-3: Version bump looks good.

The patch version increment from 3.0.0 to 3.0.1 is appropriate for type hint improvements without runtime behavior changes.

tests/test_core_decorators.py (2)

49-49: Type hint correctly reflects decorator capabilities.

The | Response addition aligns with the updated decorator signatures, even though this specific route doesn't return a Response object. The type hint accurately represents what the decorator allows.


58-58: Type hint correctly reflects decorator capabilities.

The | Response addition aligns with the updated decorator signatures, even though this specific route doesn't return a Response object. The type hint accurately represents what the decorator allows.

fasthx/htmy.py (2)

141-141: Type signature correctly propagates Response support.

The signature update to accept and return T | Response properly reflects the decorator's capability to handle routes that may return Response objects directly, aligning with the core decorator changes.


166-166: Type signature correctly propagates Response support.

The signature update to accept and return T | Response properly reflects the decorator's capability to handle routes that may return Response objects directly, aligning with the core decorator changes.

fasthx/core_decorators.py (4)

19-19: Type signature correctly reflects runtime behavior.

The signature update to return Callable[[MaybeAsyncFunc[P, T | Response]], Callable[P, Coroutine[None, None, T | Response]]] accurately represents that routes can return either T or Response, with the existing runtime logic at line 58 already handling Response objects by returning them directly.


34-36: Inner decorator signature properly accepts Response returns.

The updated signature MaybeAsyncFunc[P, T | Response] correctly reflects that the decorated function can return a Response object, which is already handled by the runtime check at line 58.


89-89: Type signature correctly reflects runtime behavior.

The signature update to return Callable[[MaybeAsyncFunc[P, T | Response]], Callable[P, Coroutine[None, None, Response]]] accurately represents that routes can return either T or Response, with the existing runtime logic at line 114 already handling Response objects by returning them directly.


99-99: Inner decorator signature properly accepts Response returns.

The updated signature MaybeAsyncFunc[P, T | Response] correctly reflects that the decorated function can return a Response object, which is already handled by the runtime check at line 114.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 17fbdcf and e30275d.

📒 Files selected for processing (2)
  • .github/workflows/tests.yml (1 hunks)
  • tests/test_htmy.py (1 hunks)
🔇 Additional comments (1)
.github/workflows/tests.yml (1)

13-13: LGTM! Job name now matches the workflow purpose.

The rename from "Linters" to "Tests" accurately reflects what this job does and aligns with the workflow filename.

Comment on lines +41 to +43
def htmx_or_data(
response: Response,
) -> list[User]:
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.

@volfpeter volfpeter merged commit a9ccadb into main Oct 12, 2025
3 checks passed
@volfpeter volfpeter deleted the feat/allow-Response-in-route-type-hints branch October 12, 2025 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants