diff --git a/docs/versionhistory.rst b/docs/versionhistory.rst index df92f51d..05e69a09 100644 --- a/docs/versionhistory.rst +++ b/docs/versionhistory.rst @@ -11,6 +11,9 @@ This library adheres to `Semantic Versioning 2.0 `_. 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 `_) **4.6.2** diff --git a/src/anyio/_core/_fileio.py b/src/anyio/_core/_fileio.py index 53d3288c..ef2930e4 100644 --- a/src/anyio/_core/_fileio.py +++ b/src/anyio/_core/_fileio.py @@ -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 diff --git a/tests/test_fileio.py b/tests/test_fileio.py index 61725a47..f5d0183b 100644 --- a/tests/test_fileio.py +++ b/tests/test_fileio.py @@ -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)