2626from types import TracebackType
2727from typing import Any , Callable , Coroutine , Optional , Union
2828
29- from aenum import Enum
29+ from aenum import Enum # type: ignore
3030from aiohttp import ClientResponse , ClientResponseError
3131from aiohttp import ClientSession as AioHttpClientSession
3232from aiohttp import ServerConnectionError
@@ -77,18 +77,18 @@ def __init__(
7777 self .__retry_number = max_retry_number
7878 self .__retry_delay = base_retry_delay
7979
80- async def __nothing (self ):
80+ async def __nothing (self ) -> None :
8181 pass
8282
83- def __sleep (self , retry_num : int , retry_factor : int ) -> Coroutine :
84- if retry_num > 0 : # don't wait at the first retry attempt
83+ def __sleep (self , retry_num : int , retry_factor : Optional [ int ] ) -> Coroutine :
84+ if retry_num > 0 and retry_factor is not None : # don't wait at the first retry attempt
8585 delay = (((retry_factor * self .__retry_delay ) * 1000 ) ** retry_num ) / 1000
8686 return asyncio .sleep (delay )
8787 else :
8888 return self .__nothing ()
8989
9090 async def __request (
91- self , method : Callable [[ Any , dict [ str , Any ]], Coroutine [Any , Any , ClientResponse ]], url , ** kwargs : Any
91+ self , method : Callable [..., Coroutine [Any , Any , ClientResponse ]], url : str , ** kwargs : Any
9292 ) -> ClientResponse :
9393 """Make a request and retry if necessary.
9494
@@ -100,7 +100,7 @@ async def __request(
100100 exceptions = []
101101
102102 for i in range (self .__retry_number + 1 ): # add one for the first attempt, which is not a retry
103- retry_factor = None
103+ retry_factor : Optional [ int ] = None
104104 if result is not None :
105105 # Release previous result to return connection to pool
106106 result .release ()
@@ -138,6 +138,8 @@ async def __request(
138138 raise exceptions [- 1 ]
139139 else :
140140 raise exceptions [0 ]
141+ if result is None :
142+ raise IOError ("Request failed without exceptions" )
141143 return result
142144
143145 def get (self , url : str , * , allow_redirects : bool = True , ** kwargs : Any ) -> Coroutine [Any , Any , ClientResponse ]:
0 commit comments