Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type annotate the tests (using monkeytype and manual fixes) #301

Merged
merged 12 commits into from
Jun 5, 2021
2 changes: 0 additions & 2 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.
**UNRELEASED**

- Fixed the type annotation of ``open_signal_receiver()`` as a synchronous context manager
- Fixed the type annotations of ``AsyncFile.__aiter__``, ``readline``, ``write` to also accept/return ``str``
and also fixed ``AsyncFile.writelines`` to take an ``Iterable[str|bytes]`` rather than ``bytes``
- Fixed the type annotation of ``DeprecatedAwaitable(|List|Float).__await__`` to match the ``typing.Awaitable`` protocol

**3.1.0**
Expand Down
12 changes: 6 additions & 6 deletions src/anyio/_core/_fileio.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from os import PathLike
from typing import Any, AsyncIterator, Callable, Generic, Iterable, List, Optional, TypeVar, Union
from typing import Any, AsyncIterator, Callable, Generic, Optional, TypeVar, Union

from .. import to_thread
from ..abc import AsyncResource
Expand Down Expand Up @@ -51,7 +51,7 @@ def wrapped(self) -> T_Fp:
"""The wrapped file object."""
return self._fp

async def __aiter__(self) -> AsyncIterator[Union[bytes, str]]:
async def __aiter__(self) -> AsyncIterator[bytes]:
while True:
line = await self.readline()
if line:
Expand All @@ -68,10 +68,10 @@ async def read(self, size: int = -1) -> Union[bytes, str]:
async def read1(self, size: int = -1) -> Union[bytes, str]:
return await to_thread.run_sync(self._fp.read1, size)

async def readline(self) -> Union[bytes, str]:
async def readline(self) -> bytes:
return await to_thread.run_sync(self._fp.readline)

async def readlines(self) -> List[Union[bytes, str]]:
async def readlines(self) -> bytes:
return await to_thread.run_sync(self._fp.readlines)

async def readinto(self, b: Union[bytes, memoryview]) -> bytes:
Expand All @@ -80,10 +80,10 @@ async def readinto(self, b: Union[bytes, memoryview]) -> bytes:
async def readinto1(self, b: Union[bytes, memoryview]) -> bytes:
return await to_thread.run_sync(self._fp.readinto1, b)

async def write(self, b: Union[bytes, str]) -> None:
async def write(self, b: bytes) -> None:
return await to_thread.run_sync(self._fp.write, b)

async def writelines(self, lines: Iterable[Union[bytes, str]]) -> None:
async def writelines(self, lines: bytes) -> None:
return await to_thread.run_sync(self._fp.writelines, lines)

async def truncate(self, size: Optional[int] = None) -> int:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ async def test_async_iteration(tmp_path: PosixPath) -> None:
async with await open_file(str(testpath)) as f:
lines_i = iter(lines)
async for line in f:
assert line == next(lines_i)
assert line == next(lines_i) # type: ignore[comparison-overlap]
agronholm marked this conversation as resolved.
Show resolved Hide resolved