Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Commit

Permalink
Fix typing for ConnectionError.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamsorcerer committed Aug 8, 2021
1 parent ed06034 commit bea076b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions aioredis/connection.py
Expand Up @@ -23,6 +23,7 @@
Type,
TypeVar,
Union,
cast,
)
from urllib.parse import ParseResult, parse_qs, unquote, urlparse

Expand Down Expand Up @@ -214,7 +215,7 @@ def on_connect(self, connection: "Connection"):
async def can_read(self, timeout: float) -> bool:
raise NotImplementedError()

async def read_response(self) -> Union[EncodableT, ResponseError, None]:
async def read_response(self) -> Union[EncodableT, ResponseError, None, List[EncodableT]]:
raise NotImplementedError()


Expand Down Expand Up @@ -516,11 +517,12 @@ async def read_from_socket(
return False
raise ConnectionError(f"Error while reading from socket: {ex.args}")

async def read_response(self) -> EncodableT:
async def read_response(self) -> Union[EncodableT, List[EncodableT]]:
if not self._stream or not self._reader:
self.on_disconnect()
raise ConnectionError(SERVER_CLOSED_CONNECTION_ERROR) from None

response: Union[EncodableT, ConnectionError, List[Union[EncodableT, ConnectionError]]]
# _next_response might be cached from a can_read() call
if self._next_response is not False:
response = self._next_response
Expand All @@ -538,12 +540,13 @@ async def read_response(self) -> EncodableT:
if isinstance(response, ConnectionError):
raise response
elif (
isinstance(response, list) # type: ignore[unreachable]
isinstance(response, list)
and response
and isinstance(response[0], ConnectionError)
):
raise response[0]
return response
# cast as there won't be a ConnectionError here.
return cast(Union[EncodableT, List[EncodableT]], response)


DefaultParser: Type[Union[PythonParser, HiredisParser]]
Expand Down

0 comments on commit bea076b

Please sign in to comment.