Skip to content

Commit 6224525

Browse files
committed
Fixed the return type annotations of AsyncFile.readinto(1)
Fixes #825.
1 parent e3acd02 commit 6224525

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

docs/versionhistory.rst

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.
1111
an object with a ``.fileno()`` method or an integer handle, and deprecated
1212
their now obsolete versions (``wait_socket_readable()`` and
1313
``wait_socket_writable()`` (PR by @davidbrochart)
14+
- Fixed the return type annotations of ``readinto()`` and ``readinto1()`` methods in the
15+
``anyio.AsyncFile`` class
16+
(`#825 <https://github.com/agronholm/anyio/issues/825>`_)
1417

1518
**4.6.2**
1619

src/anyio/_core/_fileio.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ async def readline(self) -> AnyStr:
9292
async def readlines(self) -> list[AnyStr]:
9393
return await to_thread.run_sync(self._fp.readlines)
9494

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

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

101101
@overload

tests/test_fileio.py

+12
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ async def test_read(self, testdatafile: pathlib.Path, testdata: bytes) -> None:
3939
assert f.closed
4040
assert data == testdata
4141

42+
async def test_readinto(self, testdatafile: pathlib.Path, testdata: bytes) -> None:
43+
buffer = bytearray(100)
44+
async with await open_file(testdatafile, "rb") as f:
45+
assert await f.readinto(buffer) == 100
46+
assert bytes(buffer) == testdata[:100]
47+
48+
async def test_readinto1(self, testdatafile: pathlib.Path, testdata: bytes) -> None:
49+
buffer = bytearray(100)
50+
async with await open_file(testdatafile, "rb") as f:
51+
assert await f.readinto1(buffer) == 100
52+
assert bytes(buffer) == testdata[:100]
53+
4254
async def test_write(self, testdatafile: pathlib.Path, testdata: bytes) -> None:
4355
async with await open_file(testdatafile, "ab") as f:
4456
await f.write(b"f" * 1000)

0 commit comments

Comments
 (0)