Repository: aio-libs/aiohttp

Issue:
"Iterator[BodyPartReader]" has no attribute "__anext__"
🐞 **Describe the bug**
<!-- A clear and concise description of what the bug is, on the next line. -->
`BodyPartReader.__aiter__()` is declared to return `Iterator` instead of `AsyncIterator`. Introduced in https://github.com/aio-libs/aiohttp/commit/3b70bad264da8e47974264863a09d6a5fc808b39 (#4931).


💡 **To Reproduce**
<!-- How to reproduce the behavior?

For example:
1. Have certain environment
2. Run given code snippet in a certain way
3. See some behavior described

Add these steps below this comment: -->

Snippet to reproduce:

```Python
# rep.py
from aiohttp import web

async def handler(request: web.Request) -> None:
    reader = await request.multipart()
    async for field in reader:
        ...
```


💡 **Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->

No errors returned by mypy.

📋 **Logs/tracebacks**
<!-- If applicable, add logs/tracebacks to help explain your problem. -->
```python-traceback (paste your traceback in the next line)
$ mypy rep.py
rep.py:5: error: "Iterator[BodyPartReader]" has no attribute "__anext__"; maybe "__next__"?
Found 1 error in 1 file (checked 1 source file)
```

📋 **Your version of the Python**
<!-- Attach your version of the Python. -->
```console
$ python --version
Python 3.8.6
```

📋 **Your version of the aiohttp/yarl/multidict distributions**
<!-- Attach your version of the distributions in the code blocks below. -->
```console
$ python -m pip show aiohttp
Name: aiohttp
Version: 3.7.2
Summary: Async http client/server framework (asyncio)
Home-page: https://github.com/aio-libs/aiohttp
Author: Nikolay Kim
Author-email: fafhrd91@gmail.com
License: Apache 2
Location: /private/tmp/aiohttpbug/.venv/lib/python3.8/site-packages
Requires: multidict, chardet, yarl, async-timeout, typing-extensions, attrs
Required-by:
```
```console
$ python -m pip show multidict
# irrelevant
```
```console
$ python -m pip show yarl
# irrelevant
```

📋 **Additional context**
<!-- Add any other context about the problem here, in the next line. -->

<!-- Describe the environment you have that lead to your issue.
     This includes aiohttp version, OS, proxy server and other bits that
     are related to your case.

     IMPORTANT: aiohttp is both server framework and client library.
     For getting rid of confusing please put 'server', 'client' or 'both'
     word here.
     -->

Version of mypy:

```console
$ python -m pip show mypy
Name: mypy
Version: 0.790
Summary: Optional static typing for Python
Home-page: http://www.mypy-lang.org/
Author: Jukka Lehtosalo
Author-email: jukka.lehtosalo@iki.fi
License: MIT License
Location: /private/tmp/aiohttpbug/.venv/lib/python3.8/site-packages
Requires: typed-ast, typing-extensions, mypy-extensions
Required-by:
```



Discussion:

Resolving patch:
diff --git a/aiohttp/multipart.py b/aiohttp/multipart.py
--- a/aiohttp/multipart.py
+++ b/aiohttp/multipart.py
@@ -10,6 +10,7 @@
 from typing import (
     TYPE_CHECKING,
     Any,
+    AsyncIterator,
     Dict,
     Iterator,
     List,
@@ -271,7 +272,7 @@ def __init__(
         self._content_eof = 0
         self._cache = {}  # type: Dict[str, Any]
 
-    def __aiter__(self) -> Iterator["BodyPartReader"]:
+    def __aiter__(self) -> AsyncIterator["BodyPartReader"]:
         return self  # type: ignore
 
     async def __anext__(self) -> bytes:
@@ -583,7 +584,7 @@ def __init__(
 
     def __aiter__(
         self,
-    ) -> Iterator["BodyPartReader"]:
+    ) -> AsyncIterator["BodyPartReader"]:
         return self  # type: ignore
 
     async def __anext__(


Test patch: