Closed Nadock closed 1 year ago
Hi, what version have you tested? And can you check our main branch?
This was tested on 1.51.6
and I've also been able to reproduce this when installing 06c50d7 from main
, all using Python 3.11.1
.
I actually came across the cause of this today, and it will be fixed for 2.0.
The handler gets a reference to its signature here:
However, support for resolving types in inspect.Signature.from_callable()
is only available in 3.10+.
We go on to use an isinstance()
check on the return annotation, but it is still a string here:
This will be fixed in 2.0 from this commit: https://github.com/starlite-api/starlite/pull/1160/commits/1ce9c5a84a0836139a2570317855b9a14d15d808 - and a few of the preceding commits on that branch.
We could do some eval()
work to try to resolve the type of the return annotation in the 1.5x branch, but I'd suggest that you don't rely to heavily on __future__.annotations
anywhere that there needs to be runtime introspection of types on the 1.x series.
If there's a fix coming in 2.0
that's excellent 👏
We could do some eval() work to try to resolve the type of the return annotation in the 1.5x branch, but I'd suggest that you don't rely to heavily on future.annotations anywhere that there needs to be runtime introspection of types on the 1.x series.
Yeah that's fine honestly. This was my first foray into using Starlite so I the side effects of __future__.annotations
weren't clear. Maybe worth a note in the documentation that __future__.annotations
can cause issues, but it doesn't sound like back porting a fix is that worth it.
Describe the bug If you include
from __future__ import annotations
in the same file as a route handler that returns astarlite.Template
the template will not be rendered. Instead, thestarlite.Template
object is converted to JSON and that is returned instead.To Reproduce Below is code that reproduces the error for me.
Additional context With the
from __future__ import annotations
line:Without the
from __future__ import annotations
line:I've only just started using Starlite so I'm not sure if there is something I missed in the documentation that says you shouldn't use
from __future__ import annotations
. But even if there is, maybe Starlite could raise an exception when you do this.