Skip to content

reflex.event: revert future annotation changes#6254

Merged
masenf merged 2 commits intomainfrom
masenf/revert-future-annotations-event
Mar 27, 2026
Merged

reflex.event: revert future annotation changes#6254
masenf merged 2 commits intomainfrom
masenf/revert-future-annotations-event

Conversation

@masenf
Copy link
Copy Markdown
Collaborator

@masenf masenf commented Mar 27, 2026

Go back to string-based annotations, to unbreak reflex-web

Go back to string-based annotations, to unbreak reflex-web
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 27, 2026

Merging this PR will not alter performance

βœ… 8 untouched benchmarks


Comparing masenf/revert-future-annotations-event (12333b6) with main (1e78f2c)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (23d9a09) during the generation of this report, so 1e78f2c was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 27, 2026

Greptile Summary

This PR reverts the from __future__ import annotations addition to reflex/event.py (which had made all annotations lazily evaluated strings) and instead adds explicit string literals only where forward references or TYPE_CHECKING-gated imports require them.

Key changes:

  • from __future__ import annotations removed from the top of reflex/event.py.
  • ~30 annotations converted to string form to handle forward references:
    • Classes used before their definition: "EventHandler" (defined at line 274, referenced at lines 102/116/155), "EventSpec" (defined at line 407, referenced from EventHandler.__call__), "EventVar" / "EventCallback" (referenced in EventChain.events before their definitions at lines 2116/2349).
    • Type alias used before definition: "EventType" (defined at line 2483, referenced at lines 565/1484/1525/1561).
    • TYPE_CHECKING-only import: "BaseState" (only available under TYPE_CHECKING block, used in get_event and get_hydrate_event).
    • Self-referencing return types in EventSpec.with_args, EventSpec.add_args, LiteralEventVar.create, LiteralEventChainVar.create, and the EventCallback overloads.
  • All remaining (non-string) annotations reference types imported directly at module level (Var, ArgsSpec, Sequence, Callable, etc.) and are safe to evaluate at runtime without the __future__ import.

Confidence Score: 5/5

Safe to merge β€” this is a focused, mechanical revert with all forward references correctly wrapped in string literals.

All changed annotations have been reviewed: every forward reference (types defined later in the file) and every TYPE_CHECKING-only import is now in string form, while annotations referencing directly-imported types remain unquoted. No logic, behavior, or public API is altered. No P0/P1 findings.

No files require special attention.

Important Files Changed

Filename Overview
reflex/event.py Removes from __future__ import annotations and replaces all forward-reference annotations with explicit string literals β€” a mechanical but correct revert that restores runtime-resolvable annotations throughout the file.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["from __future__ import annotations\n(removed)"] -->|"was lazily evaluated"| B["All annotations treated as strings at runtime"]
    B -->|"revert"| C["Explicit string literals added to\nforward-reference annotations"]
    C --> D1["'EventHandler' β€” used before class def at line 274"]
    C --> D2["'EventSpec' β€” used before class def at line 407"]
    C --> D3["'EventVar'/'EventCallback' β€” forward refs in EventChain.events"]
    C --> D4["'EventType' β€” TypeAliasType defined at line 2483, used earlier"]
    C --> D5["'BaseState' β€” only imported under TYPE_CHECKING"]
    D1 & D2 & D3 & D4 & D5 --> E["Annotations correctly resolved\nat runtime without __future__"]
Loading

Reviews (1): Last reviewed commit: "reflex.event: revert future annotation c..." | Re-trigger Greptile

this allows the test to run with the actual proposed reflex version instead of
replacing it back to main
@masenf masenf merged commit 4f9675f into main Mar 27, 2026
45 of 47 checks passed
@masenf masenf deleted the masenf/revert-future-annotations-event branch March 27, 2026 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants