From c6244bf058de4f178aa30a37be74b453dd56a483 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sat, 17 Aug 2024 10:26:44 -0400 Subject: [PATCH] don't use yield; touch up documentation --- asyncio/core.py | 8 +++++--- asyncio/event.py | 2 -- asyncio/funcs.py | 6 +++--- asyncio/lock.py | 2 -- asyncio/stream.py | 22 +++------------------- 5 files changed, 11 insertions(+), 29 deletions(-) diff --git a/asyncio/core.py b/asyncio/core.py index 8a4eb1d..2409d8f 100644 --- a/asyncio/core.py +++ b/asyncio/core.py @@ -96,7 +96,9 @@ def sleep_ms(t, sgen=SingletonGenerator()): # CIRCUITPY-CHANGE: doc """Sleep for *t* milliseconds. - This is a coroutine, and a MicroPython extension. + This is a MicroPython extension. + + Returns a coroutine. """ # CIRCUITPY-CHANGE: add debugging hint @@ -108,9 +110,9 @@ def sleep_ms(t, sgen=SingletonGenerator()): # Pause task execution for the given time (in seconds) def sleep(t): # CIRCUITPY-CHANGE: doc - """Sleep for *t* seconds + """Sleep for *t* seconds. - This is a coroutine. + Returns a coroutine. """ return sleep_ms(int(t * 1000)) diff --git a/asyncio/event.py b/asyncio/event.py index 1cb1a30..bd63cb9 100644 --- a/asyncio/event.py +++ b/asyncio/event.py @@ -57,8 +57,6 @@ async def wait(self): # CIRCUITPY-CHANGE: doc """Wait for the event to be set. If the event is already set then it returns immediately. - - This is a coroutine. """ if not self.state: diff --git a/asyncio/funcs.py b/asyncio/funcs.py index e3c20c3..582ffc2 100644 --- a/asyncio/funcs.py +++ b/asyncio/funcs.py @@ -42,8 +42,6 @@ async def wait_for(aw, timeout, sleep=core.sleep): this should be trapped by the caller. Returns the return value of *aw*. - - This is a coroutine. """ aw = core._promote_to_task(aw) @@ -80,7 +78,9 @@ def wait_for_ms(aw, timeout): # CIRCUITPY-CHANGE: doc """Similar to `wait_for` but *timeout* is an integer in milliseconds. - This is a coroutine, and a MicroPython extension. + This is a MicroPython extension. + + Returns a coroutine. """ return wait_for(aw, timeout, core.sleep_ms) diff --git a/asyncio/lock.py b/asyncio/lock.py index 6dc8bbc..2320ebb 100644 --- a/asyncio/lock.py +++ b/asyncio/lock.py @@ -67,8 +67,6 @@ async def acquire(self): # CIRCUITPY-CHANGE: doc """Wait for the lock to be in the unlocked state and then lock it in an atomic way. Only one task can acquire the lock at any one time. - - This is a coroutine. """ if self.state != 0: diff --git a/asyncio/stream.py b/asyncio/stream.py index 24523b6..0d2e249 100644 --- a/asyncio/stream.py +++ b/asyncio/stream.py @@ -43,8 +43,6 @@ def close(self): async def wait_closed(self): # CIRCUITPY-CHANGE: doc """Wait for the stream to close. - - This is a coroutine. """ # TODO yield? @@ -54,8 +52,6 @@ async def wait_closed(self): async def read(self, n): # CIRCUITPY-CHANGE: doc """Read up to *n* bytes and return them. - - This is a coroutine. """ await core._io_queue.queue_read(self.s) @@ -67,7 +63,7 @@ async def readinto(self, buf): Return the number of bytes read into *buf* - This is a coroutine, and a MicroPython extension. + This is a MicroPython extension. """ # CIRCUITPY-CHANGE: await, not yield @@ -81,9 +77,7 @@ async def readexactly(self, n): Raises an ``EOFError`` exception if the stream ends before reading *n* bytes. - - This is a coroutine. - """ + """ r = b"" while n: @@ -101,8 +95,6 @@ async def readexactly(self, n): async def readline(self): # CIRCUITPY-CHANGE: doc """Read a line and return it. - - This is a coroutine. """ l = b"" @@ -133,8 +125,6 @@ def write(self, buf): async def drain(self): # CIRCUITPY-CHANGE: doc """Drain (write) all buffered output data out to the stream. - - This is a coroutine. """ mv = memoryview(self.out_buf) @@ -162,8 +152,6 @@ async def open_connection(host, port, ssl=None, server_hostname=None): Returns a pair of streams: a reader and a writer stream. Will raise a socket-specific ``OSError`` if the host could not be resolved or if the connection could not be made. - - This is a coroutine. """ from uerrno import EINPROGRESS @@ -188,7 +176,7 @@ async def open_connection(host, port, ssl=None, server_hostname=None): s = ssl.wrap_socket(s, server_hostname=server_hostname, do_handshake_on_connect=False) s.setblocking(False) ss = Stream(s) - yield core._io_queue.queue_write(s) + await core._io_queue.queue_write(s) return ss, ss @@ -214,8 +202,6 @@ def close(self): async def wait_closed(self): """Wait for the server to close. - - This is a coroutine. """ await self.task @@ -263,8 +249,6 @@ async def start_server(cb, host, port, backlog=5): writer streams for the connection. Returns a `Server` object. - - This is a coroutine. """ import socket