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 16, 2020
1 parent 23da8fd commit bc090e1
Show file tree
Hide file tree
Showing 3 changed files with 12 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__.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Andrii Soldatenko
Antoine Pietri
Anton Kasyanov
Anton Zhdan-Pushkin
Arseny Timoniq
Artem Yushkovskiy
Arthur Darcet
Ben Bader
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 @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bc090e1

Please sign in to comment.