Skip to content

Commit da90e33

Browse files
authored
docs: 📝 Better documentation for latency properties (#2653)
📝 Better documentation for latency methods
1 parent 1b2972b commit da90e33

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

discord/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ def _handle_ready(self) -> None:
310310

311311
@property
312312
def latency(self) -> float:
313-
"""Measures latency between a HEARTBEAT and a HEARTBEAT_ACK in seconds.
313+
"""Measures latency between a HEARTBEAT and a HEARTBEAT_ACK in seconds. If no websocket
314+
is present, this returns ``nan``, and if no heartbeat has been received yet, this returns ``float('inf')``.
314315
315316
This could be referred to as the Discord WebSocket protocol latency.
316317
"""

discord/gateway.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,9 @@ async def received_message(self, msg, /):
581581

582582
@property
583583
def latency(self) -> float:
584-
"""Measures latency between a HEARTBEAT and a HEARTBEAT_ACK in seconds."""
584+
"""Measures latency between a HEARTBEAT and a HEARTBEAT_ACK in seconds. If no heartbeat
585+
has been received yet this returns ``float('inf')``.
586+
"""
585587
heartbeat = self._keep_alive
586588
return float("inf") if heartbeat is None else heartbeat.latency
587589

discord/shard.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,9 @@ async def connect(self) -> None:
294294

295295
@property
296296
def latency(self) -> float:
297-
"""Measures latency between a HEARTBEAT and a HEARTBEAT_ACK in seconds for this shard."""
297+
"""Measures latency between a HEARTBEAT and a HEARTBEAT_ACK in seconds for this shard. If no heartbeat
298+
has been received yet this returns ``float('inf')``.
299+
"""
298300
return self._parent.ws.latency
299301

300302
def is_ws_ratelimited(self) -> bool:

0 commit comments

Comments
 (0)