Skip to content

Commit 93d3e19

Browse files
chore(typing): add type hints to SubscriptionHandle (#2574)
Signed-off-by: Harshit Saraan <harshitsaraan@gmail.com>
1 parent 212178b commit 93d3e19

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

src/hiero_sdk_python/utils/subscription_handle.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ class SubscriptionHandle:
1111
Calling .cancel() will signal the subscription thread to stop.
1212
"""
1313

14-
def __init__(self):
14+
def __init__(self) -> None:
1515
self._cancelled = threading.Event()
1616
self._thread: threading.Thread | None = None
1717
self._call: Any | None = None
1818
self._lock = threading.Lock()
1919

20-
def _set_call(self, call: Any):
20+
def _set_call(self, call: Any) -> None:
2121
"""Sets the active gRPC call so it can be cancelled."""
2222
should_cancel = False
2323

@@ -27,10 +27,10 @@ def _set_call(self, call: Any):
2727
if call is not None and self._cancelled.is_set():
2828
should_cancel = True
2929

30-
if should_cancel:
30+
if should_cancel and self._call is not None:
3131
self._call.cancel()
3232

33-
def cancel(self):
33+
def cancel(self) -> None:
3434
"""Signals to cancel the subscription."""
3535
should_cancel = False
3636

@@ -40,18 +40,22 @@ def cancel(self):
4040
if self._call is not None:
4141
should_cancel = True
4242

43-
if should_cancel:
43+
if should_cancel and self._call is not None:
4444
self._call.cancel()
4545

4646
def is_cancelled(self) -> bool:
4747
"""Returns True if this subscription is already cancelled."""
4848
return self._cancelled.is_set()
4949

50-
def set_thread(self, thread: threading.Thread):
50+
def set_thread(self, thread: threading.Thread) -> None:
5151
"""(Optional) Store the thread object for reference."""
5252
self._thread = thread
5353

54-
def join(self, timeout=None):
55-
"""(Optional) Wait for the subscription thread to end."""
54+
def join(self, timeout: float | None = None) -> None:
55+
"""(Optional) Wait for the subscription thread to end.
56+
57+
Args:
58+
timeout (float | None): Wait time in seconds.
59+
"""
5660
if self._thread:
5761
self._thread.join(timeout)

0 commit comments

Comments
 (0)