-
-
Notifications
You must be signed in to change notification settings - Fork 395
docs: add missing docstrings for public API #3404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
3da0288
77edca2
1743878
dcfa304
54c94dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Added missing docstrings for public API classes and methods. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,6 +118,22 @@ def __init__(self, max_buffer_size: int | float) -> None: # noqa: PYI041 | |
|
|
||
| @attrs.frozen | ||
| class MemoryChannelStatistics: | ||
| """Statistics about a memory channel. | ||
|
|
||
| Returned by :meth:`MemorySendChannel.statistics` and | ||
| :meth:`MemoryReceiveChannel.statistics`. | ||
|
|
||
| Attributes: | ||
| current_buffer_used: The number of items currently buffered in the channel. | ||
| max_buffer_size: The maximum number of items that can be buffered. | ||
| open_send_channels: The number of open | ||
| :class:`MemorySendChannel` endpoints. | ||
| open_receive_channels: The number of open | ||
| :class:`MemoryReceiveChannel` endpoints. | ||
| tasks_waiting_send: The number of tasks waiting to send. | ||
| tasks_waiting_receive: The number of tasks waiting to receive. | ||
| """ | ||
|
|
||
| current_buffer_used: int | ||
| max_buffer_size: int | float | ||
| open_send_channels: int | ||
|
|
@@ -152,6 +168,14 @@ def statistics(self) -> MemoryChannelStatistics: | |
| @final | ||
| @attrs.define(eq=False, repr=False, slots=False) | ||
| class MemorySendChannel(SendChannel[SendType], metaclass=NoPublicConstructor): | ||
| """The send end of a memory channel, created by | ||
| :func:`open_memory_channel`. | ||
|
|
||
| See :ref:`channels` for details. This implements the | ||
| :class:`trio.abc.SendChannel` interface. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO "this implements ..." is unnecessary. Do we do that elsewhere? |
||
|
|
||
| """ | ||
|
|
||
| _state: MemoryChannelState[SendType] | ||
| _closed: bool = False | ||
| # This is just the tasks waiting on *this* object. As compared to | ||
|
|
@@ -300,6 +324,14 @@ async def aclose(self) -> None: | |
| @final | ||
| @attrs.define(eq=False, repr=False, slots=False) | ||
| class MemoryReceiveChannel(ReceiveChannel[ReceiveType], metaclass=NoPublicConstructor): | ||
| """The receive end of a memory channel, created by | ||
| :func:`open_memory_channel`. | ||
|
|
||
| See :ref:`channels` for details. This implements the | ||
| :class:`trio.abc.ReceiveChannel` interface. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above. |
||
|
|
||
| """ | ||
|
|
||
| _state: MemoryChannelState[ReceiveType] | ||
| _closed: bool = False | ||
| _tasks: set[trio._core._run.Task] = attrs.Factory(set) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -152,6 +152,8 @@ class ParkingLot: | |
| # items | ||
| _parked: OrderedDict[Task, None] = attrs.field(factory=OrderedDict, init=False) | ||
| broken_by: list[Task] = attrs.field(factory=list, init=False) | ||
| """List of tasks that have broken this parking lot via | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like you tried to document |
||
| :meth:`break_lot`. An empty list if the lot has not been broken.""" | ||
|
|
||
| def __len__(self) -> int: | ||
| """Returns the number of parked tasks.""" | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -107,6 +107,7 @@ def __init__(self, socket: SocketType) -> None: | |||
| self.setsockopt(tsocket.IPPROTO_TCP, tsocket.TCP_NOTSENT_LOWAT, 2**14) | ||||
|
|
||||
| async def send_all(self, data: bytes | bytearray | memoryview) -> None: | ||||
| """See :meth:`trio.abc.SendStream.send_all`.""" | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's strange, why is Sphinx making you copy-paste these? Hmmm... maybe it's the trio/docs/source/reference-io.rst Line 221 in 94d7159
I would rather fix that there instead of adding docstrings here. |
||||
| if self.socket.did_shutdown_SHUT_WR: | ||||
| raise trio.ClosedResourceError("can't send data after sending EOF") | ||||
| with self._send_conflict_detector: | ||||
|
|
@@ -124,13 +125,15 @@ async def send_all(self, data: bytes | bytearray | memoryview) -> None: | |||
| total_sent += sent | ||||
|
|
||||
| async def wait_send_all_might_not_block(self) -> None: | ||||
| """See :meth:`trio.abc.SendStream.wait_send_all_might_not_block`.""" | ||||
| with self._send_conflict_detector: | ||||
| if self.socket.fileno() == -1: | ||||
| raise trio.ClosedResourceError | ||||
| with _translate_socket_errors_to_stream_errors(): | ||||
| await self.socket.wait_writable() | ||||
|
|
||||
| async def send_eof(self) -> None: | ||||
| """See :meth:`trio.abc.HalfCloseableStream.send_eof`.""" | ||||
| with self._send_conflict_detector: | ||||
| await trio.lowlevel.checkpoint() | ||||
| # On macOS, calling shutdown a second time raises ENOTCONN, but | ||||
|
|
@@ -141,6 +144,7 @@ async def send_eof(self) -> None: | |||
| self.socket.shutdown(tsocket.SHUT_WR) | ||||
|
|
||||
| async def receive_some(self, max_bytes: int | None = None) -> bytes: | ||||
| """See :meth:`trio.abc.ReceiveStream.receive_some`.""" | ||||
| if max_bytes is None: | ||||
| max_bytes = DEFAULT_RECEIVE_SIZE | ||||
| if max_bytes < 1: | ||||
|
|
@@ -149,6 +153,7 @@ async def receive_some(self, max_bytes: int | None = None) -> bytes: | |||
| return await self.socket.recv(max_bytes) | ||||
|
|
||||
| async def aclose(self) -> None: | ||||
| """See :meth:`trio.abc.AsyncResource.aclose`.""" | ||||
| self.socket.close() | ||||
| await trio.lowlevel.checkpoint() | ||||
|
|
||||
|
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
MemorySendChannel.statisticsandMemoryReceiveChannel.statisticsdocument the attributes (iirc they do), could you remove that?(well, that's my current mood. but I'm not so sure which way is best!)