Skip to content

Commit 5efc6c8

Browse files
Specify types in set_parser() (#12073)
1 parent 11cb58a commit 5efc6c8

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

aiohttp/client_proto.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import asyncio
22
from contextlib import suppress
3-
from typing import Any, Callable
3+
from typing import Callable, Protocol
44

5+
from ._websocket.reader import WebSocketDataQueue
56
from .base_protocol import BaseProtocol
67
from .client_exceptions import (
78
ClientConnectionError,
@@ -14,6 +15,7 @@
1415
_EXC_SENTINEL,
1516
EMPTY_BODY_STATUS_CODES,
1617
BaseTimerContext,
18+
ErrorableProtocol,
1719
set_exception,
1820
set_result,
1921
)
@@ -22,6 +24,10 @@
2224
from .streams import EMPTY_PAYLOAD, DataQueue, StreamReader
2325

2426

27+
class _Payload(ErrorableProtocol, Protocol):
28+
def is_eof(self) -> bool: ...
29+
30+
2531
class ResponseHandler(BaseProtocol, DataQueue[tuple[RawResponseMessage, StreamReader]]):
2632
"""Helper class to adapt between Protocol and StreamReader."""
2733

@@ -31,7 +37,7 @@ def __init__(self, loop: asyncio.AbstractEventLoop) -> None:
3137

3238
self._should_close = False
3339

34-
self._payload: StreamReader | None = None
40+
self._payload: _Payload | None = None
3541
self._skip_payload = False
3642
self._payload_parser: WebSocketReader | None = None
3743
self._data_received_cb: Callable[[], None] | None = None
@@ -206,15 +212,10 @@ def set_exception(
206212

207213
def set_parser(
208214
self,
209-
parser: Any,
210-
payload: Any,
215+
parser: WebSocketReader,
216+
payload: WebSocketDataQueue,
211217
data_received_cb: Callable[[], None] | None = None,
212218
) -> None:
213-
# TODO: actual types are:
214-
# parser: WebSocketReader
215-
# payload: WebSocketDataQueue
216-
# but they are not generi enough
217-
# Need an ABC for both types
218219
self._payload = payload
219220
self._payload_parser = parser
220221
self._data_received_cb = data_received_cb

0 commit comments

Comments
 (0)