Repository navigation
feat(event): accept any sequence of events where a list of them is accepted - #7402
Conversation
[Medium impact] The PR appears safe to merge; the dependency-floor change addresses the outstanding import failure. SummaryThe PR lets event props, returned events, page loaders, and internal forms accept non-string sequences.
Reviews (15) · Last reviewed commit: "build(internal): require the reflex that..." · Reviewed by Greptile |
Merging this PR will degrade performance by 4.05%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ | test_hydration_snapshot[200] |
8.6 ms | 8.9 ms | -4.05% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing benedikt-bartscher:event-sequences (dc13e2e) with main (81f463b)
…per, so the declared reflex floor still type-checks
There was a problem hiding this comment.
All reported issues were addressed across 13 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
… of splitting it into characters
call_event_fn only split a list or tuple, so a lambda returning another sequence such as a UserList was wrapped as one event and rejected.
is_non_string_sequence checks list and tuple before the Sequence ABC, and excludes bytes as well as str. _check_valid_yield uses it instead of its own copy of the check. from_event_type, fix_events and call_event_fn wrap a single event through one _event_sequence helper. EventChain.create keeps its own branches, so a bad top-level value still reports "Invalid event chain". The demo and intro forms drop the string guard: the type already excludes a str, and the event chain rejects one anyway. Tests cover a handler that returns or yields a tuple through the event processor, and which values count as a sequence.
There was a problem hiding this comment.
All reported issues were addressed across 10 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
View guided diff | Re-trigger cubic
reflex/app.py imports is_non_string_sequence, which reflex-base 0.10.0 lacks.
…_sequence" pin-exact rewrites the reflex-base requirement to == <version> at build time, so a released reflex never installs with an older reflex-base.
The demo and intro forms turn their on_submit into a list of events with reflex_base.event.event_sequence instead of their own isinstance check.
# Conflicts: # packages/reflex-components-internal/src/reflex_components_internal/blocks/demo_form.py # tests/type_checking/event.py # tests/units/reflex_components_internal/blocks/test_demo_form.py
There was a problem hiding this comment.
All reported issues were addressed across 5 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
The demo and intro forms import event_sequence, which reflex 0.10.0 and older lack.
An event prop accepted a list literal of events, but not a list variable:
EventTypespelled its list formlist[...]of every kind of event, and lists areinvariant, so a
list[EventSpec]or alist[EventCallback[()]]is not one of those.At runtime the same holds for tuples:
EventChain.create,format_queue_events,Event.from_event_typeandfix_eventsonly took alist, whilecall_event_fnalready took a tuple from a lambda and
_check_valid_yieldalready let a handlerreturn a tuple (
return a, b), whichfrom_event_typethen rejected as anunexpected event type.
EventTypenow spells itSequence[...], which is covariant, and those placestake any sequence other than a string through
is_non_string_sequence, aTypeIshelper in
reflex_base.utils.types, so the runtime accepts exactly what the typedoes. A
Varis not aSequence, so nothing that was a single event becomes asequence. A page's
on_load(App._commit_page) reads the value the same way, soon_load=(a, b)registers both events instead of one tuple. The internal demo andintro forms check their
on_submitagainstSequencedirectly, since theirdeclared
reflexfloor predates the helper, and reject a string up front.from_event_typeruns for every event a handler returns, so it checks the singleevent kinds before the
SequenceABC, as_check_valid_yielddoes: a singleEvent,EventSpecor callable costs what it did with thelistcheck.tests/type_checking/event.pypasses alist[EventSpec]variable and a tuple ofhandlers to an
EventType[()]parameter; it fails under pyright and ty before thischange. Unit tests cover a tuple in each of the runtime places, the full unit suite
and pyright pass.