Skip to content

Commit 0bc5014

Browse files
committed
chore: make loop a property
1 parent c88cac8 commit 0bc5014

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

discord/client.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def __init__(
231231
):
232232
# self.ws is set in the connect method
233233
self.ws: DiscordWebSocket = None # type: ignore
234-
self.loop: asyncio.AbstractEventLoop = loop
234+
self._loop: asyncio.AbstractEventLoop = loop
235235
self._listeners: dict[str, list[tuple[asyncio.Future, Callable[..., bool]]]] = (
236236
{}
237237
)
@@ -323,6 +323,19 @@ def _get_state(self, **options: Any) -> ConnectionState:
323323
def _handle_ready(self) -> None:
324324
self._ready.set()
325325

326+
@property
327+
def loop(self) -> asyncio.AbstractEventLoop:
328+
"""The event loop that the client uses for asynchronous operations."""
329+
if self._loop is MISSING:
330+
raise RuntimeError('loop is not set')
331+
return self._loop
332+
333+
@loop.setter
334+
def loop(self, value: asyncio.AbstractEventLoop) -> None:
335+
if not isinstance(value, asyncio.AbstractEventLoop):
336+
raise TypeError(f'expected a AbstractEventLoop object, got {value.__class__.__name__!r} instead')
337+
self._loop = value
338+
326339
@property
327340
def latency(self) -> float:
328341
"""Measures latency between a HEARTBEAT and a HEARTBEAT_ACK in seconds. If no websocket

0 commit comments

Comments
 (0)