diff --git a/CHANGES/4931.bugfix b/CHANGES/4931.bugfix new file mode 100644 index 00000000000..2b54fb4eb8a --- /dev/null +++ b/CHANGES/4931.bugfix @@ -0,0 +1 @@ +Fix typings for multipart __aiter__. diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 6d5c267b813..ad471fcd6e8 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -40,6 +40,7 @@ Andrii Soldatenko Antoine Pietri Anton Kasyanov Anton Zhdan-Pushkin +Arseny Timoniq Artem Yushkovskiy Arthur Darcet Ben Bader diff --git a/aiohttp/multipart.py b/aiohttp/multipart.py index 7b01bf1f742..c38e8d443d0 100644 --- a/aiohttp/multipart.py +++ b/aiohttp/multipart.py @@ -162,7 +162,7 @@ def unescape(text: str, *, def content_disposition_filename(params: Mapping[str, str], - name: str='filename') -> Optional[str]: + name: str = 'filename') -> Optional[str]: name_suf = '%s*' % name if not params: return None @@ -265,8 +265,8 @@ def __init__( self._content_eof = 0 self._cache = {} # type: Dict[str, Any] - def __aiter__(self) -> 'BodyPartReader': - return self + def __aiter__(self) -> Iterator['BodyPartReader']: + return self # type: ignore async def __anext__(self) -> bytes: part = await self.next() @@ -280,7 +280,7 @@ async def next(self) -> Optional[bytes]: return None return item - async def read(self, *, decode: bool=False) -> bytes: + async def read(self, *, decode: bool = False) -> bytes: """Reads body part data. decode: Decodes data following by encoding @@ -296,7 +296,7 @@ async def read(self, *, decode: bool=False) -> bytes: return self.decode(data) return data - async def read_chunk(self, size: int=chunk_size) -> bytes: + async def read_chunk(self, size: int = chunk_size) -> bytes: """Reads body part content chunk of the specified size. size: chunk size @@ -577,12 +577,14 @@ def __init__( self._at_bof = True self._unread = [] # type: List[bytes] - def __aiter__(self) -> 'MultipartReader': - return self + def __aiter__( + self, + ) -> Iterator['BodyPartReader']: + return self # type: ignore async def __anext__( self, - ) -> Union['MultipartReader', BodyPartReader]: + ) -> Optional[Union['MultipartReader', BodyPartReader]]: part = await self.next() if part is None: raise StopAsyncIteration # NOQA