From 2c2724690ddcf2e0ec9a536fdc81e6f06efb1863 Mon Sep 17 00:00:00 2001 From: hasnaat Date: Sun, 28 Jun 2026 14:15:56 +0500 Subject: [PATCH 1/2] fix(core): rename parameter f to _f in _handle to prevent keyword argument collisions --- fasthtml/core.py | 4 ++-- nbs/api/00_core.ipynb | 6 +++--- tests/test_core.py | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 tests/test_core.py diff --git a/fasthtml/core.py b/fasthtml/core.py index ebf03fd2..c1b7a798 100644 --- a/fasthtml/core.py +++ b/fasthtml/core.py @@ -276,8 +276,8 @@ def __init__(self, f, skip=None): self.f,self.skip = f,skip or [] def __repr__(self): return f'Beforeware({self.f}, skip={self.skip})' # %% ../nbs/api/00_core.ipynb #78c3c357 -async def _handle(f, *args, **kwargs): - return (await f(*args, **kwargs)) if is_async_callable(f) else await run_in_threadpool(f, *args, **kwargs) +async def _handle(_f, *args, **kwargs): + return (await _f(*args, **kwargs)) if is_async_callable(_f) else await run_in_threadpool(_f, *args, **kwargs) # %% ../nbs/api/00_core.ipynb #ad0f0e87 async def _wrap_ws(ws, data, params): diff --git a/nbs/api/00_core.ipynb b/nbs/api/00_core.ipynb index 33df5c20..c451aa7b 100644 --- a/nbs/api/00_core.ipynb +++ b/nbs/api/00_core.ipynb @@ -1132,8 +1132,8 @@ "outputs": [], "source": [ "#| export\n", - "async def _handle(f, *args, **kwargs):\n", - " return (await f(*args, **kwargs)) if is_async_callable(f) else await run_in_threadpool(f, *args, **kwargs)" + "async def _handle(_f, *args, **kwargs):\n", + " return (await _f(*args, **kwargs)) if is_async_callable(_f) else await run_in_threadpool(_f, *args, **kwargs)" ] }, { @@ -4865,4 +4865,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} +} \ No newline at end of file diff --git a/tests/test_core.py b/tests/test_core.py new file mode 100644 index 00000000..14a16eb7 --- /dev/null +++ b/tests/test_core.py @@ -0,0 +1,16 @@ +from fasthtml.common import * +from starlette.testclient import TestClient + +app, rt = fast_app() +cli = TestClient(app) + +@rt("/test-f") +def post(f: str): + return Titled("Success", P(f"Value: {f}")) + +def test_argument_f_collision(): + res = cli.post('/test-f', data={'f': 'hello'}) + assert res.status_code == 200 + assert 'Value: hello' in res.text + +test_argument_f_collision() From 31337f38db89cdd6dc239f4a7224b128a933121c Mon Sep 17 00:00:00 2001 From: hasnaat Date: Tue, 30 Jun 2026 23:42:57 +0500 Subject: [PATCH 2/2] test: move test for wrapper f collision to 00_core.ipynb notebook and delete test_core.py --- nbs/api/00_core.ipynb | 10 +++++++++- tests/test_core.py | 16 ---------------- 2 files changed, 9 insertions(+), 17 deletions(-) delete mode 100644 tests/test_core.py diff --git a/nbs/api/00_core.ipynb b/nbs/api/00_core.ipynb index c451aa7b..de029f96 100644 --- a/nbs/api/00_core.ipynb +++ b/nbs/api/00_core.ipynb @@ -2496,7 +2496,15 @@ "def get(): return H1('bar')\n", "\n", "txt = cli.get('/xt2').text\n", - "assert 'FastHTML page' in txt and '

bar

' in txt and '' in txt" + "assert 'FastHTML page' in txt and '

bar

' in txt and '' in txt\n", + "\n", + "@rt('/test-f')\n", + "def post(f: str):\n", + " return Titled('Success', P(f'Value: {f}'))\n", + "\n", + "res = cli.post('/test-f', data={'f': 'hello'})\n", + "assert res.status_code == 200\n", + "assert 'Value: hello' in res.text\n" ] }, { diff --git a/tests/test_core.py b/tests/test_core.py deleted file mode 100644 index 14a16eb7..00000000 --- a/tests/test_core.py +++ /dev/null @@ -1,16 +0,0 @@ -from fasthtml.common import * -from starlette.testclient import TestClient - -app, rt = fast_app() -cli = TestClient(app) - -@rt("/test-f") -def post(f: str): - return Titled("Success", P(f"Value: {f}")) - -def test_argument_f_collision(): - res = cli.post('/test-f', data={'f': 'hello'}) - assert res.status_code == 200 - assert 'Value: hello' in res.text - -test_argument_f_collision()