Skip to content

Type checking against asyncssh using mypy 1.0.0 fails. #539

Closed

Description

@jonathanslenders

See: python/mypy#14631

I'm opening an issue here as well, to discuss it from the asyncssh side.

So, basically: mypy -c 'import asyncssh' fails.

The code in question which I think is problematic is this:
https://github.com/ronf/asyncssh/blob/develop/asyncssh/connection.py#L181

Activity

  1. jonathanslenders commented on Feb 7, 2023

    @jonathanslenders
    Author

    It looks like not using a _ConnectionFactory prevents mypy from crashing. This is a fix:

    diff --git a/asyncssh/connection.py b/asyncssh/connection.py
    index 898652b..fc91eb6 100644
    --- a/asyncssh/connection.py
    +++ b/asyncssh/connection.py
    @@ -179,7 +179,7 @@ _ServerFactory = Callable[[], SSHServer]
     _ProtocolFactory = Union[_ClientFactory, _ServerFactory]
    
     _Conn = TypeVar('_Conn', 'SSHClientConnection', 'SSHServerConnection')
    -_ConnectionFactory = Callable[[], _Conn]
    
     class _TunnelProtocol(Protocol):
         """Base protocol for connections to tunnel SSH over"""
    @@ -269,7 +269,7 @@ _DEFAULT_MAX_LINE_LENGTH = 1024     # 1024 characters
    
     async def _open_proxy(
             loop: asyncio.AbstractEventLoop, command: Sequence[str],
    -        conn_factory: _ConnectionFactory[_Conn]) -> _Conn:
    +        conn_factory: Callable[[], _Conn]) -> _Conn:
         """Open a tunnel running a proxy command"""
    
         class _ProxyCommandTunnel(asyncio.SubprocessProtocol):
    @@ -376,7 +376,7 @@ async def _open_tunnel(tunnel: object, passphrase: Optional[BytesOrStr]) -> \
     async def _connect(options: 'SSHConnectionOptions',
                        loop: asyncio.AbstractEventLoop, flags: int,
                        sock: Optional[socket.socket],
    -                   conn_factory: _ConnectionFactory[_Conn], msg: str) -> _Conn:
    +                   conn_factory: Callable[[],_Conn], msg: str) -> _Conn:
         """Make outbound TCP or SSH tunneled connection"""
    
         host = options.host
    @@ -455,7 +455,7 @@ async def _listen(options: 'SSHConnectionOptions',
                       loop: asyncio.AbstractEventLoop, flags: int,
                       backlog: int, sock: Optional[socket.socket],
                       reuse_address: bool, reuse_port: bool,
    -                  conn_factory: _ConnectionFactory[_Conn],
    +                  conn_factory: Callable[[], _Conn],
                       msg: str) -> 'SSHAcceptor':
         """Make inbound TCP or SSH tunneled listener"""
    
    jonathan@ubuntu ~/git/asyncssh [develop]
  2. ronf commented on Feb 8, 2023

    @ronf
    Owner

    Thanks for the report! It looks like there's a fix for this already proposed at python/mypy#14642, so this change may not be needed in asyncssh, but let me know if you're still running into issues after that.

  3. jonathanslenders commented on Feb 10, 2023

    @jonathanslenders
    Author

    Closing this. There is a mypy fix that got merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions