Skip to content

Commit 0dd3258

Browse files
authored
Add __aiter__ and __anext__ methods for asyncio.StreamReader (#4286)
The following code produces an error in mypy: import asyncio from asyncio.subprocess import PIPE async def main() -> None: proc = await asyncio.create_subprocess_shell("ls -l", stdout=PIPE) assert proc.stdout is not None async for line in proc.stdout: print(line.decode()) await proc.wait() asyncio.run(main()) $ mypy --strict file.py file.py:8: error: "StreamReader" has no attribute "__aiter__" (not async iterable) This commits fixes this by adding __aiter__/__anext__ methods that are needed for async iterator protocol.
1 parent ed04d33 commit 0dd3258

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

stdlib/3/asyncio/streams.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys
2-
from typing import Any, Awaitable, Callable, Iterable, Optional, Tuple, Union
2+
from typing import Any, AsyncIterator, Awaitable, Callable, Iterable, Optional, Tuple, Union
33

44
from . import events
55
from . import protocols
@@ -106,3 +106,5 @@ class StreamReader:
106106
async def readuntil(self, separator: bytes = ...) -> bytes: ...
107107
async def read(self, n: int = ...) -> bytes: ...
108108
async def readexactly(self, n: int) -> bytes: ...
109+
def __aiter__(self) -> AsyncIterator[bytes]: ...
110+
async def __anext__(self) -> bytes: ...

0 commit comments

Comments
 (0)