From 27017627b00222e80e7de9c952f6a599d3e500ed Mon Sep 17 00:00:00 2001 From: timoniq <52574917+timoniq@users.noreply.github.com> Date: Sun, 23 Aug 2020 10:51:26 +0300 Subject: [PATCH 1/2] Improve multipart.py typings for mock iter and slightly reformat --- CONTRIBUTORS.txt | 1 + aiohttp/multipart.py | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index b40c107f6cd..97c1a39b752 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 From d64e16b9b2bfd9b5e62e85e127ba0b901d9979ca Mon Sep 17 00:00:00 2001 From: timoniq <52574917+timoniq@users.noreply.github.com> Date: Sun, 23 Aug 2020 11:09:05 +0300 Subject: [PATCH 2/2] Add .bugfix to CHANGES --- CHANGES/4931.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 CHANGES/4931.bugfix 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__.