From 84c73c6a396ee462bf68f6ade1ae547a96269780 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 6 Oct 2023 13:21:10 -0700 Subject: [PATCH] Two asyncio changes that fix tests --- asyncio/funcs.py | 3 +++ asyncio/stream.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/asyncio/funcs.py b/asyncio/funcs.py index baf804d..b1bb24a 100644 --- a/asyncio/funcs.py +++ b/asyncio/funcs.py @@ -98,6 +98,9 @@ async def gather(*aws, return_exceptions=False): Returns a list of return values of all *aws* """ + if not aws: + return [] + def done(t, er): # Sub-task "t" has finished, with exception "er". nonlocal state diff --git a/asyncio/stream.py b/asyncio/stream.py index 4a9d6bf..44a8cc5 100644 --- a/asyncio/stream.py +++ b/asyncio/stream.py @@ -113,6 +113,13 @@ def write(self, buf): `Stream.drain` is called. It is recommended to call `Stream.drain` immediately after calling this function. """ + if not self.out_buf: + # Try to write immediately to the underlying stream. + ret = self.s.write(buf) + if ret == len(buf): + return + if ret is not None: + buf = buf[ret:] self.out_buf += buf