Skip to content

Commit 3da0288

Browse files
author
nightcityblade
committed
docs: add missing docstrings for public API
Add docstrings to: - MemorySendChannel class - MemoryReceiveChannel class - MemoryChannelStatistics class and attributes - SocketStream.send_all, wait_send_all_might_not_block, send_eof, receive_some, aclose - HasFileno.fileno - ParkingLot.broken_by attribute Fixes #3221
1 parent 3dd35d7 commit 3da0288

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

src/trio/_channel.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,22 @@ 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+
Returned by :meth:`MemorySendChannel.statistics` and
124+
:meth:`MemoryReceiveChannel.statistics`.
125+
126+
Attributes:
127+
current_buffer_used: The number of items currently buffered in the channel.
128+
max_buffer_size: The maximum number of items that can be buffered.
129+
open_send_channels: The number of open
130+
:class:`MemorySendChannel` endpoints.
131+
open_receive_channels: The number of open
132+
:class:`MemoryReceiveChannel` endpoints.
133+
tasks_waiting_send: The number of tasks waiting to send.
134+
tasks_waiting_receive: The number of tasks waiting to receive.
135+
"""
136+
121137
current_buffer_used: int
122138
max_buffer_size: int | float
123139
open_send_channels: int
@@ -152,6 +168,14 @@ def statistics(self) -> MemoryChannelStatistics:
152168
@final
153169
@attrs.define(eq=False, repr=False, slots=False)
154170
class MemorySendChannel(SendChannel[SendType], metaclass=NoPublicConstructor):
171+
"""The send end of a memory channel, created by
172+
:func:`open_memory_channel`.
173+
174+
See :ref:`channel` for details. This implements the
175+
:class:`trio.abc.SendChannel` interface.
176+
177+
"""
178+
155179
_state: MemoryChannelState[SendType]
156180
_closed: bool = False
157181
# This is just the tasks waiting on *this* object. As compared to
@@ -300,6 +324,14 @@ async def aclose(self) -> None:
300324
@final
301325
@attrs.define(eq=False, repr=False, slots=False)
302326
class MemoryReceiveChannel(ReceiveChannel[ReceiveType], metaclass=NoPublicConstructor):
327+
"""The receive end of a memory channel, created by
328+
:func:`open_memory_channel`.
329+
330+
See :ref:`channel` for details. This implements the
331+
:class:`trio.abc.ReceiveChannel` interface.
332+
333+
"""
334+
303335
_state: MemoryChannelState[ReceiveType]
304336
_closed: bool = False
305337
_tasks: set[trio._core._run.Task] = attrs.Factory(set)

src/trio/_core/_parking_lot.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ 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 parking lot via
156+
:meth:`break_lot`. An empty list if the lot has not been broken."""
155157

156158
def __len__(self) -> int:
157159
"""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 :meth:`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 :meth:`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 :meth:`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 :meth:`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 :meth:`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)