def _check_valid(self, handler: EventHandler, events: Any) -> Any:
        """Check if the events yielded are valid. They must be EventHandlers or EventSpecs.

        Args:
            handler: EventHandler.
            events: The events to be checked.

        Raises:
            TypeError: If any of the events are not valid.

        Returns:
            The events as they are if valid.
        """

        def _is_valid_type(events: Any) -> bool:
            return isinstance(events, (Event, EventHandler, EventSpec))

        if events is None or _is_valid_type(events):
            return events

        if not isinstance(events, Sequence):
            events = [events]

        try:
            if all(_is_valid_type(e) for e in events):
                return events
        except TypeError:
            pass

        coroutines = [e for e in events if asyncio.iscoroutine(e)]

        for coroutine in coroutines:
            coroutine_name = coroutine.__qualname__
            warnings.filterwarnings(
                "ignore", message=f"coroutine '{coroutine_name}' was never awaited"
            )

        msg = (
            f"Your handler {handler.fn.__qualname__} must only return/yield: None, Events or other EventHandlers referenced by their class (i.e. using `type(self)` or other class references)."
            f" Returned events of types {', '.join(map(str, map(type, events)))!s}."
        )
        raise TypeError(msg)
Check if the events yielded are valid. They must be EventHandlers or EventSpecs.

        Args:
            handler: EventHandler.
            events: The events to be checked.

        Raises:
            TypeError: If any of the events are not valid.

        Returns:
            The events as they are if valid.
        
reflex/state.py