77
88import  asyncio 
99import  collections 
10+ from  collections .abc  import  Callable 
1011import  enum 
1112import  functools 
1213import  getpass 
@@ -803,8 +804,23 @@ def connection_lost(self, exc: typing.Optional[Exception]) -> None:
803804 self .on_data .set_exception (exc )
804805
805806
806- async  def  _create_ssl_connection (protocol_factory , host , port , * ,
807-  loop , ssl_context , ssl_is_advisory = False ):
807+ _ProctolFactoryR  =  typing .TypeVar (
808+  "_ProctolFactoryR" , bound = asyncio .protocols .Protocol 
809+ )
810+ 
811+ 
812+ async  def  _create_ssl_connection (
813+  # TODO: The return type is a specific combination of subclasses of 
814+  # asyncio.protocols.Protocol that we can't express. For now, having the 
815+  # return type be dependent on signature of the factory is an improvement 
816+  protocol_factory : "Callable[[], _ProctolFactoryR]" ,
817+  host : str ,
818+  port : int ,
819+  * ,
820+  loop : asyncio .AbstractEventLoop ,
821+  ssl_context : ssl_module .SSLContext ,
822+  ssl_is_advisory : bool  =  False ,
823+ ) ->  typing .Tuple [asyncio .Transport , _ProctolFactoryR ]:
808824
809825 tr , pr  =  await  loop .create_connection (
810826 lambda : TLSUpgradeProto (loop , host , port ,
@@ -824,6 +840,7 @@ async def _create_ssl_connection(protocol_factory, host, port, *,
824840 try :
825841 new_tr  =  await  loop .start_tls (
826842 tr , pr , ssl_context , server_hostname = host )
843+  assert  new_tr  is  not None 
827844 except  (Exception , asyncio .CancelledError ):
828845 tr .close ()
829846 raise 
0 commit comments