37
37
from pathlib import Path
38
38
from types import TracebackType
39
39
from typing import TYPE_CHECKING , Any , AnyStr , Awaitable , Callable , Dict
40
- from typing import List , Mapping , Optional , Sequence , Set , Tuple , Type
41
- from typing import TypeVar , Union , cast
40
+ from typing import Generic , List , Mapping , Optional , Sequence , Set , Tuple
41
+ from typing import Type , TypeVar , Union , cast
42
42
from typing_extensions import Protocol , Self
43
43
44
44
from .agent import SSHAgentClient , SSHAgentListener
@@ -395,7 +395,7 @@ def close(self) -> None:
395
395
return cast (_Conn , cast (_ProxyCommandTunnel , tunnel ).get_conn ())
396
396
397
397
398
- async def _open_tunnel (tunnels : object , options : ' _Options' ,
398
+ async def _open_tunnel (tunnels : object , options : _Options ,
399
399
config : DefTuple [ConfigPaths ]) -> \
400
400
Optional ['SSHClientConnection' ]:
401
401
"""Parse and open connection to tunnel over"""
@@ -432,7 +432,7 @@ async def _open_tunnel(tunnels: object, options: '_Options',
432
432
return None
433
433
434
434
435
- async def _connect (options : ' _Options' , config : DefTuple [ConfigPaths ],
435
+ async def _connect (options : _Options , config : DefTuple [ConfigPaths ],
436
436
loop : asyncio .AbstractEventLoop , flags : int ,
437
437
sock : Optional [socket .socket ],
438
438
conn_factory : Callable [[], _Conn ], msg : str ) -> _Conn :
@@ -517,7 +517,7 @@ async def _connect(options: '_Options', config: DefTuple[ConfigPaths],
517
517
await conn .wait_closed ()
518
518
519
519
520
- async def _listen (options : ' _Options' , config : DefTuple [ConfigPaths ],
520
+ async def _listen (options : _Options , config : DefTuple [ConfigPaths ],
521
521
loop : asyncio .AbstractEventLoop , flags : int ,
522
522
backlog : int , sock : Optional [socket .socket ],
523
523
reuse_address : bool , reuse_port : bool ,
@@ -7151,7 +7151,7 @@ async def open_agent_connection(self) -> \
7151
7151
return SSHReader [bytes ](session , chan ), SSHWriter [bytes ](session , chan )
7152
7152
7153
7153
7154
- class SSHConnectionOptions (Options ):
7154
+ class SSHConnectionOptions (Options , Generic [ _Options ] ):
7155
7155
"""SSH connection options"""
7156
7156
7157
7157
config : SSHConfig
@@ -7189,12 +7189,12 @@ class SSHConnectionOptions(Options):
7189
7189
keepalive_internal : float
7190
7190
keepalive_count_max : int
7191
7191
7192
- def __init__ (self , options : Optional [' _Options' ] = None , ** kwargs : object ):
7192
+ def __init__ (self , options : Optional [_Options ] = None , ** kwargs : object ):
7193
7193
last_config = options .config if options else None
7194
7194
super ().__init__ (options = options , last_config = last_config , ** kwargs )
7195
7195
7196
7196
@classmethod
7197
- async def construct (cls , options : Optional [' _Options' ] = None ,
7197
+ async def construct (cls , options : Optional [_Options ] = None ,
7198
7198
** kwargs : object ) -> _Options :
7199
7199
"""Construct a new options object from within an async task"""
7200
7200
@@ -7355,9 +7355,7 @@ def _split_cname_patterns(
7355
7355
elif isinstance (rekey_bytes , str ):
7356
7356
rekey_bytes = parse_byte_count (rekey_bytes )
7357
7357
7358
- rekey_bytes : int
7359
-
7360
- if rekey_bytes <= 0 :
7358
+ if cast (int , rekey_bytes ) <= 0 :
7361
7359
raise ValueError ('Rekey bytes cannot be negative or zero' )
7362
7360
7363
7361
if rekey_seconds == ():
@@ -7368,9 +7366,7 @@ def _split_cname_patterns(
7368
7366
elif isinstance (rekey_seconds , str ):
7369
7367
rekey_seconds = parse_time_interval (rekey_seconds )
7370
7368
7371
- rekey_seconds : float
7372
-
7373
- if rekey_seconds and rekey_seconds <= 0 :
7369
+ if rekey_seconds and cast (float , rekey_seconds ) <= 0 :
7374
7370
raise ValueError ('Rekey seconds cannot be negative or zero' )
7375
7371
7376
7372
if isinstance (connect_timeout , str ):
@@ -7394,8 +7390,8 @@ def _split_cname_patterns(
7394
7390
if keepalive_count_max <= 0 :
7395
7391
raise ValueError ('Keepalive count max cannot be negative or zero' )
7396
7392
7397
- self .rekey_bytes = rekey_bytes
7398
- self .rekey_seconds = rekey_seconds
7393
+ self .rekey_bytes = cast ( int , rekey_bytes )
7394
+ self .rekey_seconds = cast ( float , rekey_seconds )
7399
7395
self .connect_timeout = connect_timeout or None
7400
7396
self .login_timeout = login_timeout
7401
7397
self .keepalive_interval = keepalive_interval
0 commit comments