Skip to content

Commit 6e44517

Browse files
Typing all self parameters
1 parent 0220076 commit 6e44517

File tree

2 files changed

+40
-18
lines changed

2 files changed

+40
-18
lines changed

src/replit_river/session.py

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import asyncio
22
import logging
3-
from typing import Any, Awaitable, Callable, Coroutine
3+
from typing import Any, Awaitable, Callable, Coroutine, TypeAlias
44

55
import nanoid # type: ignore
66
import websockets
@@ -36,27 +36,55 @@
3636
trace_propagator = TraceContextTextMapPropagator()
3737
trace_setter = TransportMessageTracingSetter()
3838

39+
CloseSessionCallback: TypeAlias = Callable[["Session"], Coroutine[Any, Any, Any]]
40+
RetryConnectionCallback: TypeAlias = (
41+
Callable[
42+
[],
43+
Coroutine[Any, Any, Any],
44+
]
45+
)
46+
3947

4048
class Session:
4149
"""Common functionality shared between client_session and server_session"""
4250

51+
_transport_id: str
52+
_to_id: str
53+
session_id: str
54+
_transport_options: TransportOptions
55+
56+
# session state, only modified during closing
57+
_state: SessionState
58+
_state_lock: asyncio.Lock
59+
_close_session_callback: CloseSessionCallback
60+
_close_session_after_time_secs: float | None
61+
62+
# ws state
63+
_ws_lock: asyncio.Lock
64+
_ws_wrapper: WebsocketWrapper
65+
_heartbeat_misses: int
66+
_retry_connection_callback: RetryConnectionCallback | None
67+
68+
# stream for tasks
69+
_stream_lock: asyncio.Lock
4370
_streams: dict[str, Channel[Any]]
4471

72+
# book keeping
73+
_seq_manager: SeqManager
74+
_msg_lock: asyncio.Lock
75+
_buffer: MessageBuffer
76+
_task_manager: BackgroundTaskManager
77+
78+
4579
def __init__(
4680
self,
4781
transport_id: str,
4882
to_id: str,
4983
session_id: str,
5084
websocket: websockets.WebSocketCommonProtocol,
5185
transport_options: TransportOptions,
52-
close_session_callback: Callable[["Session"], Coroutine[Any, Any, Any]],
53-
retry_connection_callback: (
54-
Callable[
55-
[],
56-
Coroutine[Any, Any, Any],
57-
]
58-
| None
59-
) = None,
86+
close_session_callback: CloseSessionCallback,
87+
retry_connection_callback: RetryConnectionCallback | None = None,
6088
) -> None:
6189
self._transport_id = transport_id
6290
self._to_id = to_id

src/replit_river/v2/client_session.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
InvalidMessageException,
3535
OutOfOrderMessageException,
3636
)
37-
from replit_river.session import Session
37+
from replit_river.session import CloseSessionCallback, RetryConnectionCallback, Session
3838
from replit_river.transport_options import MAX_MESSAGE_BUFFER_SIZE, TransportOptions
3939

4040
STREAM_CANCEL_BIT_TYPE = Literal[0b00100]
@@ -54,14 +54,8 @@ def __init__(
5454
session_id: str,
5555
websocket: websockets.WebSocketCommonProtocol,
5656
transport_options: TransportOptions,
57-
close_session_callback: Callable[[Session], Coroutine[Any, Any, Any]],
58-
retry_connection_callback: (
59-
Callable[
60-
[],
61-
Coroutine[Any, Any, Any],
62-
]
63-
| None
64-
) = None,
57+
close_session_callback: CloseSessionCallback,
58+
retry_connection_callback: RetryConnectionCallback | None = None,
6559
) -> None:
6660
super().__init__(
6761
transport_id=transport_id,

0 commit comments

Comments
 (0)