diff --git a/src/textual/signal.py b/src/textual/signal.py index cc1be10b52..daa7b28108 100644 --- a/src/textual/signal.py +++ b/src/textual/signal.py @@ -18,7 +18,7 @@ if TYPE_CHECKING: from textual.dom import DOMNode - from textual.message_pump import MessagePump + SignalT = TypeVar("SignalT") SignalCallbackType = Union[ @@ -44,7 +44,7 @@ def __init__(self, owner: DOMNode, name: str) -> None: self._owner = ref(owner) self._name = name self._subscriptions: WeakKeyDictionary[ - MessagePump, list[SignalCallbackType] + DOMNode, list[SignalCallbackType[SignalT]] ] = WeakKeyDictionary() def __rich_repr__(self) -> rich.repr.Result: @@ -59,8 +59,8 @@ def owner(self) -> DOMNode | None: def subscribe( self, - node: MessagePump, - callback: SignalCallbackType, + node: DOMNode, + callback: SignalCallbackType[SignalT], immediate: bool = False, ) -> None: """Subscribe a node to this signal. @@ -84,20 +84,20 @@ def subscribe( if immediate: - def signal_callback(data: object) -> None: + def signal_callback(data: SignalT) -> None: """Invoke the callback immediately.""" callback(data) else: - def signal_callback(data: object) -> None: + def signal_callback(data: SignalT) -> None: """Post the callback to the node, to call at the next opertunity.""" node.call_next(callback, data) callbacks = self._subscriptions.setdefault(node, []) callbacks.append(signal_callback) - def unsubscribe(self, node: MessagePump) -> None: + def unsubscribe(self, node: DOMNode) -> None: """Unsubscribe a node from this signal. Args: