mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 04:34:28 +08:00
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.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import sys
|
||||
from typing import Any, Awaitable, Callable, Iterable, Optional, Tuple, Union
|
||||
from typing import Any, AsyncIterator, Awaitable, Callable, Iterable, Optional, Tuple, Union
|
||||
|
||||
from . import events
|
||||
from . import protocols
|
||||
@@ -106,3 +106,5 @@ class StreamReader:
|
||||
async def readuntil(self, separator: bytes = ...) -> bytes: ...
|
||||
async def read(self, n: int = ...) -> bytes: ...
|
||||
async def readexactly(self, n: int) -> bytes: ...
|
||||
def __aiter__(self) -> AsyncIterator[bytes]: ...
|
||||
async def __anext__(self) -> bytes: ...
|
||||
|
||||
Reference in New Issue
Block a user