Skip to content

Conversation

@erikgaas
Copy link
Contributor

Fixes #814.

Previously, return type annotations like -> Titled would cause a TypeError: 'tuple' object is not callable because FastHTML tried to call the annotation as a constructor.

The fix: only use the return type annotation for wrapping when it's actually a Response subclass. This makes sense because the wrapping code passes status_code as a keyword argument, which only Response subclasses accept.

@gitnotebooks
Copy link

gitnotebooks bot commented Jan 16, 2026

Found 1 changed notebook. Review the changes at https://app.gitnotebooks.com/AnswerDotAI/fasthtml/pull/823

@erikgaas erikgaas added the bug Something isn't working label Jan 16, 2026
if not resp: resp=''
if hasattr(resp, '__response__'): resp = resp.__response__(req)
if cls in (Any,FT): cls=empty
if not (isinstance(cls, type) and issubclass(cls, Response)): cls=empty
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Any, and FT checks are covered in isisntance type check. the type checking is required or else issubclass Response will throw an error.

@erikgaas
Copy link
Contributor Author

I could also see this however as suppressing errors if someone expects some type of behavior. so we could throw an error? but this seems along the lines of what was intended for now

@jph00
Copy link
Contributor

jph00 commented Jan 31, 2026

Good idea! :)

@jph00 jph00 merged commit ac1a0a7 into main Jan 31, 2026
2 checks passed
@jph00 jph00 deleted the erikgaas/fix-return-type-annotation branch January 31, 2026 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Tighter type annotations on route return types triggers starlette error

3 participants