Repository navigation
Pass a trigger's arguments only to a callable's positional parameters - #7961
FarhanAliRaza wants to merge 3 commits into
Conversation
A callable given to an event trigger, such as `lambda key, **kw: ...` or `lambda key, *, flag=1: ...`, raised TypeError because every parameter, keyword-only and `**kwargs` included, was counted as a slot for the trigger's arguments. `*args` now takes all of them, even none. Claude-Session: https://claude.ai/code/session_01LwJUCVxPh3ihrnaFn6CWnf
[Medium impact] The PR appears safe to merge. SummaryThe PR passes trigger arguments only to a callable’s positional parameters.
No new actionable issues were found. Tests were inspected but not run. Reviews (3) · Last reviewed commit: "Reject a callable whose keyword-only par..." · Reviewed by Greptile |
Counting only positional parameters let `def handle(self, value, *, required)` bind to a one-argument trigger and fail later in the backend. Only `*args` and `**kwargs` are left out of the count now. Claude-Session: https://claude.ai/code/session_01LwJUCVxPh3ihrnaFn6CWnf
There was a problem hiding this comment.
All reported issues were addressed across 3 files
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
A function given to an event trigger gets the trigger's arguments by position, so a required keyword-only parameter can never be filled. It failed with a TypeError when the event fired; it now fails when the page is built, with an error that names the parameter and the fix. Claude-Session: https://claude.ai/code/session_01LwJUCVxPh3ihrnaFn6CWnf
Merging this PR will degrade performance by 5.65%3 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
|
CodSpeed: the 4 flagged benchmarks don't run this PR's code. CodSpeed flags I counted calls to those four functions with a None of the flagged benchmarks makes a single call into the changed code. CodSpeed's own warnings say these 4 benchmarks "ran on different hardware" and "in a different software environment" than their baseline. The first commit (81d3b35), which carried most of the change, reported no performance change. So this looks like runner variance. It can be acknowledged on CodSpeed; there's no code to fix here. Generated by Claude Code |
Type of change
What changed
A callable passed to an event trigger was given the trigger's arguments by counting every parameter of the callable as a slot, including keyword-only parameters and
**kwargs. So these raisedTypeError:call_event_fnnow passes the trigger's arguments only to the positional parameters (POSITIONAL_ONLY/POSITIONAL_OR_KEYWORD).*argstakes all of them, including none, solambda *args: ...also works on a trigger with no arguments (on_mount).EventFnArgMismatchErrorthat names the parameter and the fix (give it a default, or move it before the*). Before, it failed with a rawTypeErrorwhen the event fired.check_fn_match_arg_specno longer counts*argsand**kwargsas required arguments. A keyword-only parameter without a default still counts as required, sodef handle(self, value, *, required)on a one-argument trigger is still rejected when the page is built. A state handler's arguments are sent by name.Split out of the JS-modules PR (#7950), whose imported JS functions take
*args. That PR carries this change until this one merges.Tests
tests/units/reflex_base/event/test_init.pyhas four new regression tests:*argswith 0 and 2 trigger arguments.**kwargsand a keyword-only parameter with a default.The tests compare each full error message. Each one fails without the change it covers and passes now.
100% line and branch coverage of the changed lines. Ruff, pyright and C901 (max 8) are clean.
https://claude.ai/code/session_01LwJUCVxPh3ihrnaFn6CWnf