Skip to content

Commit

Permalink
Fixed the return type annotations of AsyncFile.readinto(1)
Browse files Browse the repository at this point in the history
Fixes #825.
  • Loading branch information
agronholm committed Nov 17, 2024
1 parent e3acd02 commit 6224525
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.
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 the return type annotations of ``readinto()`` and ``readinto1()`` methods in the
``anyio.AsyncFile`` class
(`#825 <https://github.com/agronholm/anyio/issues/825>`_)

**4.6.2**

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 6224525

Please sign in to comment.