Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve typings for multipart.py #4931

Merged
merged 2 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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