@@ -230,7 +230,7 @@ def __init__(
230
230
real_response_class = ClientResponse
231
231
else :
232
232
real_response_class = response_class
233
- self .response_class = real_response_class # type : Type[ClientResponse]
233
+ self .response_class : Type [ClientResponse ] = real_response_class
234
234
self ._timer = timer if timer is not None else TimerNoop ()
235
235
self ._ssl = ssl
236
236
@@ -265,9 +265,7 @@ def ssl(self) -> Union["SSLContext", None, bool, Fingerprint]:
265
265
def connection_key (self ) -> ConnectionKey :
266
266
proxy_headers = self .proxy_headers
267
267
if proxy_headers :
268
- h = hash (
269
- tuple ((k , v ) for k , v in proxy_headers .items ())
270
- ) # type: Optional[int]
268
+ h : Optional [int ] = hash (tuple ((k , v ) for k , v in proxy_headers .items ()))
271
269
else :
272
270
h = None
273
271
return ConnectionKey (
@@ -292,7 +290,7 @@ def port(self) -> Optional[int]:
292
290
293
291
@property
294
292
def request_info (self ) -> RequestInfo :
295
- headers = CIMultiDictProxy (self .headers ) # type: CIMultiDictProxy[str]
293
+ headers : CIMultiDictProxy [ str ] = CIMultiDictProxy (self .headers )
296
294
return RequestInfo (self .url , self .method , headers , self .original_url )
297
295
298
296
def update_host (self , url : URL ) -> None :
@@ -323,7 +321,7 @@ def update_version(self, version: Union[http.HttpVersion, str]) -> None:
323
321
324
322
def update_headers (self , headers : Optional [LooseHeaders ]) -> None :
325
323
"""Update request headers."""
326
- self .headers = CIMultiDict () # type : CIMultiDict[str]
324
+ self .headers : CIMultiDict [str ] = CIMultiDict ()
327
325
328
326
# add host
329
327
netloc = cast (str , self .url .raw_host )
@@ -363,7 +361,7 @@ def update_cookies(self, cookies: Optional[LooseCookies]) -> None:
363
361
if not cookies :
364
362
return
365
363
366
- c = SimpleCookie () # type : SimpleCookie[str]
364
+ c : SimpleCookie [str ] = SimpleCookie ()
367
365
if hdrs .COOKIE in self .headers :
368
366
c .load (self .headers .get (hdrs .COOKIE , "" ))
369
367
del self .headers [hdrs .COOKIE ]
@@ -652,14 +650,17 @@ async def _on_headers_request_sent(
652
650
653
651
class ClientResponse (HeadersMixin ):
654
652
653
+ # Some of these attributes are None when created,
654
+ # but will be set by the start() method.
655
+ # As the end user will likely never see the None values, we cheat the types below.
655
656
# from the Status-Line of the response
656
657
version = None # HTTP-Version
657
- status = None # type: int # Status-Code
658
+ status : int = None # type: ignore[assignment] # Status-Code
658
659
reason = None # Reason-Phrase
659
660
660
- content = None # type: StreamReader # Payload stream
661
- _headers = None # type: CIMultiDictProxy[str] # Response headers
662
- _raw_headers = None # type: RawHeaders # Response raw headers
661
+ content : StreamReader = None # type: ignore[assignment] # Payload stream
662
+ _headers : CIMultiDictProxy [ str ] = None # type: ignore[assignment]
663
+ _raw_headers : RawHeaders = None # type: ignore[assignment]
663
664
664
665
_connection = None # current connection
665
666
_source_traceback = None
@@ -685,22 +686,22 @@ def __init__(
685
686
super ().__init__ ()
686
687
687
688
self .method = method
688
- self .cookies = SimpleCookie () # type : SimpleCookie[str]
689
+ self .cookies : SimpleCookie [str ] = SimpleCookie ()
689
690
690
691
self ._real_url = url
691
692
self ._url = url .with_fragment (None )
692
- self ._body = None # type : Optional[bytes]
693
- self ._writer = writer # type : Optional[asyncio.Task[None]]
693
+ self ._body : Optional [bytes ] = None
694
+ self ._writer : Optional [asyncio .Task [None ]] = writer
694
695
self ._continue = continue100 # None by default
695
696
self ._closed = True
696
- self ._history = () # type : Tuple[ClientResponse, ...]
697
+ self ._history : Tuple [ClientResponse , ...] = ()
697
698
self ._request_info = request_info
698
699
self ._timer = timer if timer is not None else TimerNoop ()
699
- self ._cache = {} # type : Dict[str, Any]
700
+ self ._cache : Dict [str , Any ] = {}
700
701
self ._traces = traces
701
702
self ._loop = loop
702
703
# store a reference to session #1985
703
- self ._session = session # type : Optional[ClientSession]
704
+ self ._session : Optional [ClientSession ] = session
704
705
if loop .get_debug ():
705
706
self ._source_traceback = traceback .extract_stack (sys ._getframe (1 ))
706
707
@@ -790,7 +791,7 @@ def links(self) -> "MultiDictProxy[MultiDictProxy[Union[str, URL]]]":
790
791
if not links_str :
791
792
return MultiDictProxy (MultiDict ())
792
793
793
- links = MultiDict () # type : MultiDict[MultiDictProxy[Union[str, URL]]]
794
+ links : MultiDict [MultiDictProxy [Union [str , URL ]]] = MultiDict ()
794
795
795
796
for val in re .split (r",(?=\s*<)" , links_str ):
796
797
match = re .match (r"\s*<(.*)>(.*)" , val )
@@ -800,7 +801,7 @@ def links(self) -> "MultiDictProxy[MultiDictProxy[Union[str, URL]]]":
800
801
url , params_str = match .groups ()
801
802
params = params_str .split (";" )[1 :]
802
803
803
- link = MultiDict () # type : MultiDict[Union[str, URL]]
804
+ link : MultiDict [Union [str , URL ]] = MultiDict ()
804
805
805
806
for param in params :
806
807
match = re .match (r"^\s*(\S*)\s*=\s*(['\"]?)(.*?)(\2)\s*$" , param , re .M )
0 commit comments