diff --git a/fasthtml/core.py b/fasthtml/core.py index c4161028..9507243e 100644 --- a/fasthtml/core.py +++ b/fasthtml/core.py @@ -174,6 +174,7 @@ async def _find_p(req, arg:str, p:Parameter): if issubclass(anno, Request): return req if issubclass(anno, HtmxHeaders): return _get_htmx(req.headers) if issubclass(anno, Starlette): return req.scope['app'] + if _is_body(anno) and 'session'.startswith(arg.lower()): return req.scope.get('session', {}) if _is_body(anno): return await _from_body(req, p) # If there's no annotation, check for special names if anno is empty: diff --git a/tests/test_toaster.py b/tests/test_toaster.py index c3d3414a..8b018c5c 100644 --- a/tests/test_toaster.py +++ b/tests/test_toaster.py @@ -19,6 +19,10 @@ def post(session): def get(session): return Titled("Hello, world!", P(str(session))) +@rt("/see-toast-with-typehint") +def get(session: dict): + return Titled("Hello, world!", P(str(session))) + @rt("/see-toast-ft-response") def get(session): add_toast(session, "Toast FtResponse", "info") @@ -41,6 +45,13 @@ def test_ft_response(): res = cli.get('/see-toast-ft-response') assert 'Toast FtResponse' in res.text +def test_get_toaster_with_typehint(): + res = cli.get('/see-toast-with-typehint', follow_redirects=False) + assert 'Toast get' in res.text + + res = cli.get('/see-toast-with-typehint', follow_redirects=True) + assert 'Toast get' in res.text + test_get_toaster() test_post_toaster() test_ft_response()