Skip to content

Commit a68b8ff

Browse files
Resolving circular import
1 parent 2db0827 commit a68b8ff

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

src/replit_river/common_session.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,40 @@
11
import asyncio
2+
import enum
23
import logging
3-
from typing import Awaitable, Callable
4+
from typing import Any, Awaitable, Callable, Protocol
5+
6+
from opentelemetry.trace import Span
47

58
from replit_river.messages import FailedSendingMessageException
69
from replit_river.rpc import ACK_BIT
7-
from replit_river.session import SendMessage, SessionState
810

911
logger = logging.getLogger(__name__)
1012

1113

14+
class SendMessage(Protocol):
15+
async def __call__(
16+
self,
17+
*,
18+
stream_id: str,
19+
payload: dict[Any, Any] | str,
20+
control_flags: int,
21+
service_name: str | None,
22+
procedure_name: str | None,
23+
span: Span | None,
24+
) -> None: ...
25+
26+
27+
class SessionState(enum.Enum):
28+
"""The state a session can be in.
29+
30+
Can only transition from ACTIVE to CLOSING to CLOSED.
31+
"""
32+
33+
ACTIVE = 0
34+
CLOSING = 1
35+
CLOSED = 2
36+
37+
1238
async def setup_heartbeat(
1339
session_id: str,
1440
heartbeat_ms: float,

src/replit_river/session.py

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import asyncio
2-
import enum
32
import logging
4-
from typing import Any, Awaitable, Callable, Coroutine, Protocol
3+
from typing import Any, Awaitable, Callable, Coroutine
54

65
import nanoid # type: ignore
76
import websockets
87
from aiochannel import Channel, ChannelClosed
98
from opentelemetry.trace import Span, use_span
109
from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator
1110

12-
from replit_river.common_session import setup_heartbeat
11+
from replit_river.common_session import SessionState, setup_heartbeat
1312
from replit_river.message_buffer import MessageBuffer, MessageBufferClosedError
1413
from replit_river.messages import (
1514
FailedSendingMessageException,
@@ -36,30 +35,6 @@
3635
trace_setter = TransportMessageTracingSetter()
3736

3837

39-
class SendMessage(Protocol):
40-
async def __call__(
41-
self,
42-
*,
43-
stream_id: str,
44-
payload: dict[Any, Any] | str,
45-
control_flags: int,
46-
service_name: str | None,
47-
procedure_name: str | None,
48-
span: Span | None,
49-
) -> None: ...
50-
51-
52-
class SessionState(enum.Enum):
53-
"""The state a session can be in.
54-
55-
Can only transition from ACTIVE to CLOSING to CLOSED.
56-
"""
57-
58-
ACTIVE = 0
59-
CLOSING = 1
60-
CLOSED = 2
61-
62-
6338
class Session:
6439
"""Common functionality shared between client_session and server_session"""
6540

0 commit comments

Comments
 (0)