Skip to content

Commit 01609cc

Browse files
veeceeyclaude
andcommitted
Add missing docstrings for documented public APIs
Addresses #3221 by adding docstrings to all items that appear in the Sphinx documentation but previously had no docstring: - MemorySendChannel, MemoryReceiveChannel, MemoryChannelStatistics class docstrings - SocketStream.send_all, .receive_some, .send_eof, .wait_send_all_might_not_block, .aclose referencing parent ABCs - HasFileno.fileno docstring - ParkingLot.broken_by attribute docstring Also removes :undoc-members: from the SocketStream autoclass directive since all methods now have docstrings. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 1ee96c8 commit 01609cc

6 files changed

Lines changed: 40 additions & 2 deletions

File tree

docs/source/reference-io.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ abstraction.
218218

219219
.. autoclass:: SocketStream
220220
:members:
221-
:undoc-members:
222221
:show-inheritance:
223222

224223
.. autoclass:: SocketListener

newsfragments/3221.doc.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Added missing docstrings for `MemorySendChannel`, `MemoryReceiveChannel`,
2+
`MemoryChannelStatistics`, ``SocketStream`` methods, `~trio.lowlevel.ParkingLot.broken_by`,
3+
and ``HasFileno.fileno``.

src/trio/_channel.py

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

119119
@attrs.frozen
120120
class MemoryChannelStatistics:
121+
"""Object returned by `MemorySendChannel.statistics` and
122+
`MemoryReceiveChannel.statistics`.
123+
124+
See :func:`open_memory_channel` for details on the fields.
125+
"""
126+
121127
current_buffer_used: int
122128
max_buffer_size: int | float
123129
open_send_channels: int
@@ -152,6 +158,15 @@ def statistics(self) -> MemoryChannelStatistics:
152158
@final
153159
@attrs.define(eq=False, repr=False, slots=False)
154160
class MemorySendChannel(SendChannel[SendType], metaclass=NoPublicConstructor):
161+
"""The sending end of a memory channel.
162+
163+
Created by `open_memory_channel`. This implements the
164+
`~trio.abc.SendChannel` interface.
165+
166+
See `open_memory_channel` for details, and :ref:`channel-mpmc` for a
167+
discussion of channel cloning.
168+
"""
169+
155170
_state: MemoryChannelState[SendType]
156171
_closed: bool = False
157172
# This is just the tasks waiting on *this* object. As compared to
@@ -300,6 +315,15 @@ async def aclose(self) -> None:
300315
@final
301316
@attrs.define(eq=False, repr=False, slots=False)
302317
class MemoryReceiveChannel(ReceiveChannel[ReceiveType], metaclass=NoPublicConstructor):
318+
"""The receiving end of a memory channel.
319+
320+
Created by `open_memory_channel`. This implements the
321+
`~trio.abc.ReceiveChannel` interface.
322+
323+
See `open_memory_channel` for details, and :ref:`channel-mpmc` for a
324+
discussion of channel cloning.
325+
"""
326+
303327
_state: MemoryChannelState[ReceiveType]
304328
_closed: bool = False
305329
_tasks: set[trio._core._run.Task] = attrs.Factory(set)

src/trio/_core/_parking_lot.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ class ParkingLot:
152152
# items
153153
_parked: OrderedDict[Task, None] = attrs.field(factory=OrderedDict, init=False)
154154
broken_by: list[Task] = attrs.field(factory=list, init=False)
155+
"""List of tasks that have broken this lot via `break_lot`.
156+
157+
If empty, the lot is not broken. If non-empty, any attempt to
158+
`park` in this lot will raise `~trio.BrokenResourceError`.
159+
"""
155160

156161
def __len__(self) -> int:
157162
"""Returns the number of parked tasks."""

src/trio/_highlevel_socket.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def __init__(self, socket: SocketType) -> None:
107107
self.setsockopt(tsocket.IPPROTO_TCP, tsocket.TCP_NOTSENT_LOWAT, 2**14)
108108

109109
async def send_all(self, data: bytes | bytearray | memoryview) -> None:
110+
"""See `trio.abc.SendStream.send_all`."""
110111
if self.socket.did_shutdown_SHUT_WR:
111112
raise trio.ClosedResourceError("can't send data after sending EOF")
112113
with self._send_conflict_detector:
@@ -124,13 +125,15 @@ async def send_all(self, data: bytes | bytearray | memoryview) -> None:
124125
total_sent += sent
125126

126127
async def wait_send_all_might_not_block(self) -> None:
128+
"""See `trio.abc.SendStream.wait_send_all_might_not_block`."""
127129
with self._send_conflict_detector:
128130
if self.socket.fileno() == -1:
129131
raise trio.ClosedResourceError
130132
with _translate_socket_errors_to_stream_errors():
131133
await self.socket.wait_writable()
132134

133135
async def send_eof(self) -> None:
136+
"""See `trio.abc.HalfCloseableStream.send_eof`."""
134137
with self._send_conflict_detector:
135138
await trio.lowlevel.checkpoint()
136139
# On macOS, calling shutdown a second time raises ENOTCONN, but
@@ -141,6 +144,7 @@ async def send_eof(self) -> None:
141144
self.socket.shutdown(tsocket.SHUT_WR)
142145

143146
async def receive_some(self, max_bytes: int | None = None) -> bytes:
147+
"""See `trio.abc.ReceiveStream.receive_some`."""
144148
if max_bytes is None:
145149
max_bytes = DEFAULT_RECEIVE_SIZE
146150
if max_bytes < 1:
@@ -149,6 +153,7 @@ async def receive_some(self, max_bytes: int | None = None) -> bytes:
149153
return await self.socket.recv(max_bytes)
150154

151155
async def aclose(self) -> None:
156+
"""See `trio.abc.AsyncResource.aclose`."""
152157
self.socket.close()
153158
await trio.lowlevel.checkpoint()
154159

src/trio/_subprocess.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ def pidfd_open(fd: int, flags: int) -> int:
9898
class HasFileno(Protocol):
9999
"""Represents any file-like object that has a file descriptor."""
100100

101-
def fileno(self) -> int: ...
101+
def fileno(self) -> int:
102+
"""Return the underlying file descriptor as an integer."""
103+
...
102104

103105

104106
@final

0 commit comments

Comments
 (0)