Coverage for faststream/nats/helpers/state.py: 88%
16 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-17 21:20 +0000
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-17 21:20 +0000
1from typing import Protocol, TypeVar
3from nats.aio.client import Client
4from nats.js import JetStreamContext
6from faststream.exceptions import IncorrectState
8ClientT = TypeVar("ClientT", Client, JetStreamContext)
11class ConnectionState(Protocol[ClientT]):
12 __slots__ = ()
14 connection: ClientT
17class EmptyConnectionState(ConnectionState[ClientT]):
18 __slots__ = ()
20 @property
21 def connection(self) -> ClientT:
22 raise IncorrectState
24 @connection.setter
25 def connection(self, v: ClientT) -> None: # ruff: ignore[no-self-use]
26 raise IncorrectState
29class ConnectedState(ConnectionState[ClientT]):
30 __slots__ = ("connection",)
32 def __init__(self, connection: ClientT) -> None:
33 self.connection: ClientT = connection