Skip to content

Commit

Permalink
Fix latest mypy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ronf committed Nov 24, 2024
1 parent b99e8d5 commit fc0d3cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
28 changes: 12 additions & 16 deletions asyncssh/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
from pathlib import Path
from types import TracebackType
from typing import TYPE_CHECKING, Any, AnyStr, Awaitable, Callable, Dict
from typing import List, Mapping, Optional, Sequence, Set, Tuple, Type
from typing import TypeVar, Union, cast
from typing import Generic, List, Mapping, Optional, Sequence, Set, Tuple
from typing import Type, TypeVar, Union, cast
from typing_extensions import Protocol, Self

from .agent import SSHAgentClient, SSHAgentListener
Expand Down Expand Up @@ -395,7 +395,7 @@ def close(self) -> None:
return cast(_Conn, cast(_ProxyCommandTunnel, tunnel).get_conn())


async def _open_tunnel(tunnels: object, options: '_Options',
async def _open_tunnel(tunnels: object, options: _Options,
config: DefTuple[ConfigPaths]) -> \
Optional['SSHClientConnection']:
"""Parse and open connection to tunnel over"""
Expand Down Expand Up @@ -432,7 +432,7 @@ async def _open_tunnel(tunnels: object, options: '_Options',
return None


async def _connect(options: '_Options', config: DefTuple[ConfigPaths],
async def _connect(options: _Options, config: DefTuple[ConfigPaths],
loop: asyncio.AbstractEventLoop, flags: int,
sock: Optional[socket.socket],
conn_factory: Callable[[], _Conn], msg: str) -> _Conn:
Expand Down Expand Up @@ -517,7 +517,7 @@ async def _connect(options: '_Options', config: DefTuple[ConfigPaths],
await conn.wait_closed()


async def _listen(options: '_Options', config: DefTuple[ConfigPaths],
async def _listen(options: _Options, config: DefTuple[ConfigPaths],
loop: asyncio.AbstractEventLoop, flags: int,
backlog: int, sock: Optional[socket.socket],
reuse_address: bool, reuse_port: bool,
Expand Down Expand Up @@ -7151,7 +7151,7 @@ async def open_agent_connection(self) -> \
return SSHReader[bytes](session, chan), SSHWriter[bytes](session, chan)


class SSHConnectionOptions(Options):
class SSHConnectionOptions(Options, Generic[_Options]):
"""SSH connection options"""

config: SSHConfig
Expand Down Expand Up @@ -7189,12 +7189,12 @@ class SSHConnectionOptions(Options):
keepalive_internal: float
keepalive_count_max: int

def __init__(self, options: Optional['_Options'] = None, **kwargs: object):
def __init__(self, options: Optional[_Options] = None, **kwargs: object):
last_config = options.config if options else None
super().__init__(options=options, last_config=last_config, **kwargs)

@classmethod
async def construct(cls, options: Optional['_Options'] = None,
async def construct(cls, options: Optional[_Options] = None,
**kwargs: object) -> _Options:
"""Construct a new options object from within an async task"""

Expand Down Expand Up @@ -7355,9 +7355,7 @@ def _split_cname_patterns(
elif isinstance(rekey_bytes, str):
rekey_bytes = parse_byte_count(rekey_bytes)

rekey_bytes: int

if rekey_bytes <= 0:
if cast(int, rekey_bytes) <= 0:
raise ValueError('Rekey bytes cannot be negative or zero')

if rekey_seconds == ():
Expand All @@ -7368,9 +7366,7 @@ def _split_cname_patterns(
elif isinstance(rekey_seconds, str):
rekey_seconds = parse_time_interval(rekey_seconds)

rekey_seconds: float

if rekey_seconds and rekey_seconds <= 0:
if rekey_seconds and cast(float, rekey_seconds) <= 0:
raise ValueError('Rekey seconds cannot be negative or zero')

if isinstance(connect_timeout, str):
Expand All @@ -7394,8 +7390,8 @@ def _split_cname_patterns(
if keepalive_count_max <= 0:
raise ValueError('Keepalive count max cannot be negative or zero')

self.rekey_bytes = rekey_bytes
self.rekey_seconds = rekey_seconds
self.rekey_bytes = cast(int, rekey_bytes)
self.rekey_seconds = cast(float, rekey_seconds)
self.connect_timeout = connect_timeout or None
self.login_timeout = login_timeout
self.keepalive_interval = keepalive_interval
Expand Down
2 changes: 2 additions & 0 deletions asyncssh/sftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4341,6 +4341,8 @@ async def makedirs(self, path: _SFTPPath, attrs: SFTPAttrs = SFTPAttrs(),
parts = path.split(b'/')
last = len(parts) - 1

exc: Type[SFTPError]

for i, part in enumerate(parts):
curpath = posixpath.join(curpath, part)

Expand Down

0 comments on commit fc0d3cf

Please sign in to comment.