Skip to content

fix: type a repeated @rx.event as one handler - #7893

Open
MaiAditya wants to merge 1 commit into
reflex-dev:mainfrom
MaiAditya:fix/stacked-event-decorator-typing
Open

MaiAditya wants to merge 1 commit into
reflex-dev:mainfrom
MaiAditya:fix/stacked-event-decorator-typing

Conversation

@MaiAditya

@MaiAditya MaiAditya commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Closes #7847

The runtime has supported stacked @rx.event decorators since #7807, but the type signatures only accepted a plain function. Pyright rejected the outer decorator because its argument was the EventCallback produced by the inner one.

  • EventDecorator.__call__ (what rx.event(...) returns) gets an overload that takes EventCallback[*P] and returns EventCallback[*P]. The overload for a plain function stays as it was.
  • EventNamespace.__new__ gets the matching overload, so a bare @rx.event on top of @rx.event(...) also type-checks.
  • S.handler is now EventCallback[int] (or whatever its arguments are) whether it has one decorator or two.
  • I removed the # pyright: ignore [reportArgumentType] comments from the repeated-decorator tests in tests/units/test_event.py. The ignore on the plain-function misuse case (event(stop_propagation=True)(summarize)) now reads [reportCallIssue, reportArgumentType], the same as the event(ping) line above it, because the call now goes through overloads.
  • tests/type_checking/event.py has new assert_type examples for three stackings: @event(...) over @event(...), bare over configured, and configured over bare.

Limitation: the type of a handler read from a state class (OwnerState.handle) is the same EventCallback, so event(OwnerState.handle) now type-checks even though it raises TypeError at runtime. That test's ignore comment no longer suppresses anything, so it is replaced with a comment saying so.

Tests: on main, pyright reports 14 errors on the edited tests (7 on the stacked decorators in test_event.py, 7 on the new type_checking examples). With the fix, pyright 1.1.411 reports 0 errors on tests/units/test_event.py tests/type_checking and the event module under --pythonversion 3.11, 3.12, 3.14 and the default. pyright reflex tests reports no new errors compared with main. ty check --python-version 3.14 tests/type_checking is clean. mypy agrees on the same examples (not part of CI). pytest tests/units/test_event.py: 157 passed. Ruff check and format are clean.

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

View guided diff

The decorator returned by `rx.event(...)` and the bare `rx.event(func)`
form only accepted a plain function, so pyright rejected a second
`@rx.event` applied to the `EventCallback` the first one produced,
although the runtime merges both into one handler since reflex-dev#7807.

Add overloads that take an `EventCallback[*P]` and return it unchanged,
and drop the `# pyright: ignore` comments the repeated-decorator tests
carried. Add assert_type examples to tests/type_checking/event.py.

Closes reflex-dev#7847
@MaiAditya
MaiAditya requested a review from a team as a code owner November 13, 2026 18:41
@greptile-apps

greptile-apps Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] This PR appears safe to merge.

Summary

This PR fixes the types of stacked @rx.event decorators without changing how handlers run.

  • Stacked event decorators keep a handler’s argument types.

MaiAditya explicitly acknowledged that event(OwnerState.handle) now type-checks but still raises at runtime. This is a stated limitation, not a new review finding.

Reviews (1) · Last reviewed commit: "fix: type a repeated @rx.event as one ha..." · Reviewed by Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

View guided diff | Re-trigger cubic

@FarhanAliRaza FarhanAliRaza added the bug Something isn't working label Nov 13, 2026 — with ChatGPT Codex Connector
@codspeed

codspeed Bot commented Nov 13, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 4.97%

2 warnings

⚠️ 13 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 2 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

❌ 2 regressed benchmarks
✅ 149 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_route_matching[100] 47.7 µs 50.5 µs -5.6%
❌ test_process_event_burst_independent_tokens[1] 2.7 ms 2.8 ms -4.34%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing MaiAditya:fix/stacked-event-decorator-typing (ebaf4b5) with main (e053a7b)

Open in CodSpeed

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pyright rejects @rx.event(...) stacked above another @rx.event, although the repeated decorator is supported at runtime

2 participants