Skip to content

Commit

Permalink
Merge branch 'master' into selector-thread
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Nov 18, 2024
2 parents a379ccf + 6224525 commit 872329a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
7 changes: 5 additions & 2 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.

**UNRELEASED**

- Fixed a misleading ``ValueError`` in the context of DNS failures
(`#815 <https://github.com/agronholm/anyio/issues/815>`_; PR by @graingert)
- Added the ``wait_readable()`` and ``wait_writable()`` functions which will accept
an object with a ``.fileno()`` method or an integer handle, and deprecated
their now obsolete versions (``wait_socket_readable()`` and
``wait_socket_writable()``) (PR by @davidbrochart)
- Fixed a misleading ``ValueError`` in the context of DNS failures
(`#815 <https://github.com/agronholm/anyio/issues/815>`_; PR by @graingert)
- Fixed the return type annotations of ``readinto()`` and ``readinto1()`` methods in the
``anyio.AsyncFile`` class
(`#825 <https://github.com/agronholm/anyio/issues/825>`_)
- Ported ``ThreadSelectorEventLoop`` from Tornado to allow
``anyio.wait_readable()`` and ``anyio.wait_writable()`` to work on Windows with a
``ProactorEventLoop``.
Expand Down
4 changes: 2 additions & 2 deletions src/anyio/_core/_fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ async def readline(self) -> AnyStr:
async def readlines(self) -> list[AnyStr]:
return await to_thread.run_sync(self._fp.readlines)

async def readinto(self: AsyncFile[bytes], b: WriteableBuffer) -> bytes:
async def readinto(self: AsyncFile[bytes], b: WriteableBuffer) -> int:
return await to_thread.run_sync(self._fp.readinto, b)

async def readinto1(self: AsyncFile[bytes], b: WriteableBuffer) -> bytes:
async def readinto1(self: AsyncFile[bytes], b: WriteableBuffer) -> int:
return await to_thread.run_sync(self._fp.readinto1, b)

@overload
Expand Down
12 changes: 12 additions & 0 deletions tests/test_fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ async def test_read(self, testdatafile: pathlib.Path, testdata: bytes) -> None:
assert f.closed
assert data == testdata

async def test_readinto(self, testdatafile: pathlib.Path, testdata: bytes) -> None:
buffer = bytearray(100)
async with await open_file(testdatafile, "rb") as f:
assert await f.readinto(buffer) == 100
assert bytes(buffer) == testdata[:100]

async def test_readinto1(self, testdatafile: pathlib.Path, testdata: bytes) -> None:
buffer = bytearray(100)
async with await open_file(testdatafile, "rb") as f:
assert await f.readinto1(buffer) == 100
assert bytes(buffer) == testdata[:100]

async def test_write(self, testdatafile: pathlib.Path, testdata: bytes) -> None:
async with await open_file(testdatafile, "ab") as f:
await f.write(b"f" * 1000)
Expand Down

0 comments on commit 872329a

Please sign in to comment.