diff --git a/aiohttp/helpers.py b/aiohttp/helpers.py index 437c871e8f7..ccfa9d5e2fe 100644 --- a/aiohttp/helpers.py +++ b/aiohttp/helpers.py @@ -629,7 +629,7 @@ def register( def close(self) -> None: self._callbacks.clear() - def start(self) -> Optional[asyncio.Handle]: + def start(self) -> Optional[asyncio.TimerHandle]: timeout = self._timeout if timeout is not None and timeout > 0: when = self._loop.time() + timeout diff --git a/aiohttp/multipart.py b/aiohttp/multipart.py index da016039011..e3680a7b2a1 100644 --- a/aiohttp/multipart.py +++ b/aiohttp/multipart.py @@ -2,6 +2,7 @@ import binascii import json import re +import sys import uuid import warnings import zlib @@ -10,7 +11,6 @@ from typing import ( TYPE_CHECKING, Any, - AsyncIterator, Deque, Dict, Iterator, @@ -48,6 +48,13 @@ ) from .streams import StreamReader +if sys.version_info >= (3, 11): + from typing import Self +else: + from typing import TypeVar + + Self = TypeVar("Self", bound="BodyPartReader") + __all__ = ( "MultipartReader", "MultipartWriter", @@ -280,8 +287,8 @@ def __init__( self._content_eof = 0 self._cache: Dict[str, Any] = {} - def __aiter__(self) -> AsyncIterator["BodyPartReader"]: - return self # type: ignore[return-value] + def __aiter__(self: Self) -> Self: + return self async def __anext__(self) -> bytes: part = await self.next() @@ -581,7 +588,7 @@ class MultipartReader: response_wrapper_cls = MultipartResponseWrapper #: Multipart reader class, used to handle multipart/* body parts. #: None points to type(self) - multipart_reader_cls = None + multipart_reader_cls: Optional[Type["MultipartReader"]] = None #: Body part reader class for non multipart/* content types. part_reader_cls = BodyPartReader @@ -602,10 +609,8 @@ def __init__(self, headers: Mapping[str, str], content: StreamReader) -> None: self._at_bof = True self._unread: List[bytes] = [] - def __aiter__( - self, - ) -> AsyncIterator["BodyPartReader"]: - return self # type: ignore[return-value] + def __aiter__(self: Self) -> Self: + return self async def __anext__( self,