Skip to content

Commit 5d9067b

Browse files
authored
Add documentation for statistics() and aclose() on memory channels (#3101)
* Add documentation to document members * Clean up copy-paste * Mark new pyright checktypes error
1 parent 498325d commit 5d9067b

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

docs/source/reference-core.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,8 @@ more features beyond the core channel interface:
12411241
.. autoclass:: MemoryReceiveChannel
12421242
:members:
12431243

1244+
.. autoclass:: MemoryChannelStatistics
1245+
:members:
12441246

12451247
A simple channel example
12461248
++++++++++++++++++++++++

newsfragments/3101.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add docstrings for memory channels' ``statistics()`` and ``aclose`` methods.

src/trio/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
# Submodules imported by default
2626
from . import abc, from_thread, lowlevel, socket, to_thread
2727
from ._channel import (
28+
MemoryChannelStatistics as MemoryChannelStatistics,
2829
MemoryReceiveChannel as MemoryReceiveChannel,
2930
MemorySendChannel as MemorySendChannel,
3031
open_memory_channel as open_memory_channel,

src/trio/_channel.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def __init__(self, max_buffer_size: int | float): # noqa: PYI041
111111

112112

113113
@attrs.frozen
114-
class MemoryChannelStats:
114+
class MemoryChannelStatistics:
115115
current_buffer_used: int
116116
max_buffer_size: int | float
117117
open_send_channels: int
@@ -132,8 +132,8 @@ class MemoryChannelState(Generic[T]):
132132
# {task: None}
133133
receive_tasks: OrderedDict[Task, None] = attrs.Factory(OrderedDict)
134134

135-
def statistics(self) -> MemoryChannelStats:
136-
return MemoryChannelStats(
135+
def statistics(self) -> MemoryChannelStatistics:
136+
return MemoryChannelStatistics(
137137
current_buffer_used=len(self.data),
138138
max_buffer_size=self.max_buffer_size,
139139
open_send_channels=self.open_send_channels,
@@ -159,7 +159,9 @@ def __attrs_post_init__(self) -> None:
159159
def __repr__(self) -> str:
160160
return f"<send channel at {id(self):#x}, using buffer at {id(self._state):#x}>"
161161

162-
def statistics(self) -> MemoryChannelStats:
162+
def statistics(self) -> MemoryChannelStatistics:
163+
"""Returns a `MemoryChannelStatistics` for the memory channel this is
164+
associated with."""
163165
# XX should we also report statistics specific to this object?
164166
return self._state.statistics()
165167

@@ -282,6 +284,9 @@ def close(self) -> None:
282284

283285
@enable_ki_protection
284286
async def aclose(self) -> None:
287+
"""Close this send channel object asynchronously.
288+
289+
See `MemorySendChannel.close`."""
285290
self.close()
286291
await trio.lowlevel.checkpoint()
287292

@@ -296,7 +301,9 @@ class MemoryReceiveChannel(ReceiveChannel[ReceiveType], metaclass=NoPublicConstr
296301
def __attrs_post_init__(self) -> None:
297302
self._state.open_receive_channels += 1
298303

299-
def statistics(self) -> MemoryChannelStats:
304+
def statistics(self) -> MemoryChannelStatistics:
305+
"""Returns a `MemoryChannelStatistics` for the memory channel this is
306+
associated with."""
300307
return self._state.statistics()
301308

302309
def __repr__(self) -> str:
@@ -430,5 +437,8 @@ def close(self) -> None:
430437

431438
@enable_ki_protection
432439
async def aclose(self) -> None:
440+
"""Close this receive channel object asynchronously.
441+
442+
See `MemoryReceiveChannel.close`."""
433443
self.close()
434444
await trio.lowlevel.checkpoint()

src/trio/_tests/_check_type_completeness.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@
2020
"all": [
2121
"No docstring found for class \"trio.MemoryReceiveChannel\"",
2222
"No docstring found for class \"trio._channel.MemoryReceiveChannel\"",
23-
"No docstring found for function \"trio._channel.MemoryReceiveChannel.statistics\"",
24-
"No docstring found for class \"trio._channel.MemoryChannelStats\"",
25-
"No docstring found for function \"trio._channel.MemoryReceiveChannel.aclose\"",
23+
"No docstring found for class \"trio.MemoryChannelStatistics\"",
24+
"No docstring found for class \"trio._channel.MemoryChannelStatistics\"",
2625
"No docstring found for class \"trio.MemorySendChannel\"",
2726
"No docstring found for class \"trio._channel.MemorySendChannel\"",
28-
"No docstring found for function \"trio._channel.MemorySendChannel.statistics\"",
29-
"No docstring found for function \"trio._channel.MemorySendChannel.aclose\"",
3027
"No docstring found for class \"trio._core._run.Task\"",
3128
"No docstring found for class \"trio._socket.SocketType\"",
3229
"No docstring found for function \"trio._highlevel_socket.SocketStream.send_all\"",

0 commit comments

Comments
 (0)