typing: Provide hint for reaction type

Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Change-Id: Id054c7f9150e9c1ef8b3756d4ac9a8a2727132d6
This commit is contained in:
Stephen Finucane
2026-01-06 14:19:50 +00:00
parent b73bb3b67c
commit 7bb45f7827

View File

@@ -14,7 +14,7 @@
import collections
from collections.abc import Callable, Generator, Mapping, Sequence
from typing import Any, TypedDict
from typing import Any, Protocol, TypedDict
import prettytable
from typing_extensions import NotRequired, Self
@@ -91,10 +91,25 @@ class _Jump:
self.on_exit = on_exit
# We can't use ellipsis with concatenate until Python 3.11 so this our
# workaround
#
# https://github.com/python/cpython/pull/30969
class ReactionProtocol(Protocol):
def __call__(
self,
old_state: str | None,
new_state: str | None,
event: str,
*args: Any,
**kwargs: Any,
) -> Any: ...
class _TrackedState(TypedDict):
terminal: bool
reactions: dict[
str, tuple[Callable[..., Any], tuple[Any, ...], dict[str, Any]]
str, tuple[ReactionProtocol, tuple[Any, ...], dict[str, Any]]
]
on_enter: OnEnterCallbackT
on_exit: OnExitCallbackT