Skip to content

Commit 94de8a2

Browse files
wavebyrdclaude
andcommitted
docs: add docstrings to memory channel classes
Add docstrings to MemoryChannelStatistics, MemorySendChannel, and MemoryReceiveChannel classes so they show up properly in the Sphinx-generated documentation. - MemoryChannelStatistics: Document all attributes with descriptions - MemorySendChannel: Reference open_memory_channel and note it implements SendChannel interface - MemoryReceiveChannel: Reference open_memory_channel and note it implements ReceiveChannel interface Partial fix for #3221 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent f51968b commit 94de8a2

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

src/trio/_channel.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,26 @@ def __init__(self, max_buffer_size: int | float) -> None: # noqa: PYI041
118118

119119
@attrs.frozen
120120
class MemoryChannelStatistics:
121+
"""Statistics about a memory channel.
122+
123+
This object is returned by the ``statistics()`` method on
124+
:class:`MemorySendChannel` and :class:`MemoryReceiveChannel`.
125+
126+
Attributes:
127+
current_buffer_used: The number of items currently stored in the
128+
channel buffer.
129+
max_buffer_size: The maximum number of items allowed in the buffer,
130+
as passed to :func:`open_memory_channel`.
131+
open_send_channels: The number of open :class:`MemorySendChannel`
132+
endpoints pointing to this channel.
133+
open_receive_channels: The number of open :class:`MemoryReceiveChannel`
134+
endpoints pointing to this channel.
135+
tasks_waiting_send: The number of tasks blocked in ``send`` on this
136+
channel (summing over all clones).
137+
tasks_waiting_receive: The number of tasks blocked in ``receive`` on
138+
this channel (summing over all clones).
139+
"""
140+
121141
current_buffer_used: int
122142
max_buffer_size: int | float
123143
open_send_channels: int
@@ -152,6 +172,15 @@ def statistics(self) -> MemoryChannelStatistics:
152172
@final
153173
@attrs.define(eq=False, repr=False, slots=False)
154174
class MemorySendChannel(SendChannel[SendType], metaclass=NoPublicConstructor):
175+
"""The sending end of a memory channel.
176+
177+
Memory channels are created using :func:`open_memory_channel`, which
178+
returns a pair of (:class:`MemorySendChannel`, :class:`MemoryReceiveChannel`).
179+
See :func:`open_memory_channel` for full documentation.
180+
181+
This implements the :class:`~trio.abc.SendChannel` interface.
182+
"""
183+
155184
_state: MemoryChannelState[SendType]
156185
_closed: bool = False
157186
# This is just the tasks waiting on *this* object. As compared to
@@ -300,6 +329,15 @@ async def aclose(self) -> None:
300329
@final
301330
@attrs.define(eq=False, repr=False, slots=False)
302331
class MemoryReceiveChannel(ReceiveChannel[ReceiveType], metaclass=NoPublicConstructor):
332+
"""The receiving end of a memory channel.
333+
334+
Memory channels are created using :func:`open_memory_channel`, which
335+
returns a pair of (:class:`MemorySendChannel`, :class:`MemoryReceiveChannel`).
336+
See :func:`open_memory_channel` for full documentation.
337+
338+
This implements the :class:`~trio.abc.ReceiveChannel` interface.
339+
"""
340+
303341
_state: MemoryChannelState[ReceiveType]
304342
_closed: bool = False
305343
_tasks: set[trio._core._run.Task] = attrs.Factory(set)

0 commit comments

Comments
 (0)