reflex/tests/units/components/test_component_future_annotations.py
Khaleel Al-Adhami b2d2719f90
add type hinting to events (#4145)
* add type hinting to events

* fix pyi

* make it a list

* add on change

* dang it darglintz

* add future annotations

* add try except becuse i hate this

* add check for class

* aaaa

* sometimes you need to make hard decisions

* ono

* i hate unions

* add rx event

* move stuff around

* maybe

* special case osmething

* i don't need no test

* remove stray print

Co-authored-by: Masen Furer <m_github@0x26.net>

* remove another stray print

Co-authored-by: Masen Furer <m_github@0x26.net>

* add rx event

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
2024-10-14 08:44:31 -07:00

38 lines
1.2 KiB
Python

from __future__ import annotations
from typing import Any
from reflex.components.component import Component
from reflex.event import EventHandler, empty_event, input_event
# This is a repeat of its namesake in test_component.py.
def test_custom_component_declare_event_handlers_in_fields():
class ReferenceComponent(Component):
def get_event_triggers(self) -> dict[str, Any]:
"""Test controlled triggers.
Returns:
Test controlled triggers.
"""
return {
**super().get_event_triggers(),
"on_a": lambda e: [e],
"on_b": lambda e: [e.target.value],
"on_c": lambda e: [],
"on_d": lambda: [],
}
class TestComponent(Component):
on_a: EventHandler[lambda e0: [e0]]
on_b: EventHandler[input_event]
on_c: EventHandler[empty_event]
on_d: EventHandler[empty_event]
custom_component = ReferenceComponent.create()
test_component = TestComponent.create()
assert (
custom_component.get_event_triggers().keys()
== test_component.get_event_triggers().keys()
)