-
Notifications
You must be signed in to change notification settings - Fork 289
Description
Description
I'm moving from not have any type annotations to actually having some. However, adding stronger type annotation on route method return types triggers a starlette error.
Minimal Reproducible Example
app, rt = fast_app()
@rt("/works")
def any() -> Any:
return Titled("A Title", H2("An H2"))
@rt("/errors")
def titled() -> Titled:
return Titled("A Title", H2("An H2"))
serve()/works works. /errors gives me the following starlette error:
....*much deep stack*...
File "/Users/peter/Repository/10-19 Development/10 Development/POCs/python-code-quality/.venv/lib/python3.11/site-packages/starlette/routing.py", line 76, in app
await response(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'tuple' object is not callable
Expected behavior
I was hoping that adding a more focused type annotation would not trigger a runtime error; is starlette doing something more fancy underneath?
I've tried various alternatives (e.g. "Titled" and type-vars) and still had the same problem. Also happens irrespective of the actual component return, i.e. a method that returns a Div that's typed as such also doesn't work.
Is the section in the FAQ wrt PEP-8 and ruff indicative that the fastapi-coding style not only eschews type annotations but that they actively don't work?
Environment Information
Please provide the following version information:
- fastlite version: 0.2.2
- fastcore version: 1.9.2
- fasthtml version: 0.12.36
Confirmation
Please confirm the following:
- I have read the FAQ (https://docs.fastht.ml/explains/faq.html)
- I have provided a minimal reproducible example
- I have included the versions of fastlite, fastcore, and fasthtml
- I understand that this is a volunteer open source project with no commercial support.