Skip to content

Commit

Permalink
Improve typings for multipart.py (#4931)
Browse files Browse the repository at this point in the history
* Improve multipart.py typings for mock iter

and slightly reformat

* Add .bugfix to CHANGES
  • Loading branch information
timoniq authored and asvetlov committed Oct 15, 2020
1 parent df6cf9f commit 8877781
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGES/4931.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix typings for multipart __aiter__.
2 changes: 2 additions & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Andrii Soldatenko
Antoine Pietri
Anton Kasyanov
Anton Zhdan-Pushkin
Arseny Timoniq
Artem Yushkovskiy
Arthur Darcet
Ben Bader
Ben Timby
Expand Down
18 changes: 10 additions & 8 deletions aiohttp/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -259,8 +259,8 @@ def __init__(self, boundary: bytes,
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()
Expand All @@ -274,7 +274,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
Expand All @@ -290,7 +290,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
Expand Down Expand Up @@ -534,12 +534,14 @@ def __init__(self, headers: Mapping[str, str],
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
Expand Down

0 comments on commit 8877781

Please sign in to comment.