Skip to content

Commit eb065e0

Browse files
committed
ref(signal): use class generic for SignalCallbackType
Applies generics to the `SignalCallbackType`. Primarily to indicate what type is required, when subscribing.
1 parent 9c721dd commit eb065e0

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/textual/signal.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ def __init__(self, owner: DOMNode, name: str) -> None:
4343
"""
4444
self._owner = ref(owner)
4545
self._name = name
46-
self._subscriptions: WeakKeyDictionary[DOMNode, list[SignalCallbackType]] = (
47-
WeakKeyDictionary()
48-
)
46+
self._subscriptions: WeakKeyDictionary[
47+
DOMNode, list[SignalCallbackType[SignalT]]
48+
] = WeakKeyDictionary()
4949

5050
def __rich_repr__(self) -> rich.repr.Result:
5151
yield "owner", self.owner
@@ -60,7 +60,7 @@ def owner(self) -> DOMNode | None:
6060
def subscribe(
6161
self,
6262
node: DOMNode,
63-
callback: SignalCallbackType,
63+
callback: SignalCallbackType[SignalT],
6464
immediate: bool = False,
6565
) -> None:
6666
"""Subscribe a node to this signal.
@@ -84,13 +84,13 @@ def subscribe(
8484

8585
if immediate:
8686

87-
def signal_callback(data: object) -> None:
87+
def signal_callback(data: SignalT) -> None:
8888
"""Invoke the callback immediately."""
8989
callback(data)
9090

9191
else:
9292

93-
def signal_callback(data: object) -> None:
93+
def signal_callback(data: SignalT) -> None:
9494
"""Post the callback to the node, to call at the next opertunity."""
9595
node.call_next(callback, data)
9696

0 commit comments

Comments
 (0)