fix(core): rename parameter f to _f in _handle to prevent keyword argument collisions#897
Open
Hasnaathussain wants to merge 2 commits into
Open
Conversation
… delete test_core.py
There was a problem hiding this comment.
Pull request overview
This PR fixes a keyword-argument collision in FastHTML’s internal _handle wrapper that could raise TypeError: _handle() got multiple values for argument 'f' when a route handler accepts a parameter named f. It does so by renaming _handle’s first parameter to _f and adding a regression test in the source notebook.
Changes:
- Rename
_handle’s first parameter fromfto_fto avoid collisions with injected request/form kwargs. - Add a regression test that posts form data with key
fto a route whose handler signature includesf.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| nbs/api/00_core.ipynb | Renames _handle argument and adds an in-notebook regression test reproducing the f kwarg collision scenario. |
| fasthtml/core.py | Updates exported runtime implementation of _handle to use _f, preventing keyword collisions during handler invocation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+279
to
+280
| async def _handle(_f, *args, **kwargs): | ||
| return (await _f(*args, **kwargs)) if is_async_callable(_f) else await run_in_threadpool(_f, *args, **kwargs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
When route handlers accept an argument named
f(representing a file, form, or general parameter), invoking the handler via FastHTML's_handlefunction raisesTypeError: _handle() got multiple values for argument 'f'.This PR renames the parameter in
_handlefromfto_f(both in the source notebooknbs/api/00_core.ipynband exportedfasthtml/core.py) and integrates the regression test directly into the source notebook.Fixes #894