From 0886c4ea593d4bc17aba2131bedcd4a6e06c732c Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Wed, 2 Feb 2022 20:57:46 +0000 Subject: [PATCH] Improve classmethods in `paramiko` stubs --- stubs/paramiko/paramiko/config.pyi | 7 ++++--- stubs/paramiko/paramiko/hostkeys.pyi | 3 ++- stubs/paramiko/paramiko/pkey.pyi | 6 +++--- stubs/paramiko/paramiko/sftp_attr.pyi | 3 ++- stubs/paramiko/paramiko/sftp_client.pyi | 5 +++-- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/stubs/paramiko/paramiko/config.pyi b/stubs/paramiko/paramiko/config.pyi index 8a7b74f8b8c0..2e2bb1118fd7 100644 --- a/stubs/paramiko/paramiko/config.pyi +++ b/stubs/paramiko/paramiko/config.pyi @@ -1,3 +1,4 @@ +from _typeshed import Self from typing import IO, Any, Iterable, Pattern from paramiko.ssh_exception import ConfigParseError as ConfigParseError, CouldNotCanonicalize as CouldNotCanonicalize @@ -9,11 +10,11 @@ class SSHConfig: TOKENS_BY_CONFIG_KEY: dict[str, list[str]] def __init__(self) -> None: ... @classmethod - def from_text(cls, text: str) -> SSHConfig: ... + def from_text(cls: type[Self], text: str) -> Self: ... @classmethod - def from_path(cls, path: str) -> SSHConfig: ... + def from_path(cls: type[Self], path: str) -> Self: ... @classmethod - def from_file(cls, flo: IO[str]) -> SSHConfig: ... + def from_file(cls: type[Self], flo: IO[str]) -> Self: ... def parse(self, file_obj: IO[str]) -> None: ... def lookup(self, hostname: str) -> SSHConfigDict: ... def canonicalize(self, hostname: str, options: SSHConfigDict, domains: Iterable[str]) -> str: ... diff --git a/stubs/paramiko/paramiko/hostkeys.pyi b/stubs/paramiko/paramiko/hostkeys.pyi index 32f05bfc0ab6..8278af05418b 100644 --- a/stubs/paramiko/paramiko/hostkeys.pyi +++ b/stubs/paramiko/paramiko/hostkeys.pyi @@ -1,3 +1,4 @@ +from _typeshed import Self from typing import Iterator, Mapping, MutableMapping from paramiko.pkey import PKey @@ -41,5 +42,5 @@ class HostKeyEntry: key: PKey def __init__(self, hostnames: list[str] | None = ..., key: PKey | None = ...) -> None: ... @classmethod - def from_line(cls, line: str, lineno: int | None = ...) -> HostKeyEntry | None: ... + def from_line(cls: type[Self], line: str, lineno: int | None = ...) -> Self | None: ... def to_line(self) -> str | None: ... diff --git a/stubs/paramiko/paramiko/pkey.pyi b/stubs/paramiko/paramiko/pkey.pyi index 67eff957640d..1c060f700f51 100644 --- a/stubs/paramiko/paramiko/pkey.pyi +++ b/stubs/paramiko/paramiko/pkey.pyi @@ -36,10 +36,10 @@ class PublicBlob: comment: str def __init__(self, type_: str, blob: bytes, comment: str | None = ...) -> None: ... @classmethod - def from_file(cls, filename: str) -> PublicBlob: ... + def from_file(cls: type[Self], filename: str) -> Self: ... @classmethod - def from_string(cls, string: str) -> PublicBlob: ... + def from_string(cls: type[Self], string: str) -> Self: ... @classmethod - def from_message(cls, message: Message) -> PublicBlob: ... + def from_message(cls: type[Self], message: Message) -> Self: ... def __eq__(self, other: object) -> bool: ... def __ne__(self, other: object) -> bool: ... diff --git a/stubs/paramiko/paramiko/sftp_attr.pyi b/stubs/paramiko/paramiko/sftp_attr.pyi index 361e4f0b9930..3a397ff7168c 100644 --- a/stubs/paramiko/paramiko/sftp_attr.pyi +++ b/stubs/paramiko/paramiko/sftp_attr.pyi @@ -1,3 +1,4 @@ +from _typeshed import Self from os import stat_result class SFTPAttributes: @@ -17,5 +18,5 @@ class SFTPAttributes: attr: dict[str, str] def __init__(self) -> None: ... @classmethod - def from_stat(cls, obj: stat_result, filename: str | None = ...) -> SFTPAttributes: ... + def from_stat(cls: type[Self], obj: stat_result, filename: str | None = ...) -> Self: ... def asbytes(self) -> bytes: ... diff --git a/stubs/paramiko/paramiko/sftp_client.pyi b/stubs/paramiko/paramiko/sftp_client.pyi index fd49ff3be620..0404f38b9488 100644 --- a/stubs/paramiko/paramiko/sftp_client.pyi +++ b/stubs/paramiko/paramiko/sftp_client.pyi @@ -1,3 +1,4 @@ +from _typeshed import Self from logging import Logger from typing import IO, Any, Callable, Iterator, Text @@ -20,8 +21,8 @@ class SFTPClient(BaseSFTP, ClosingContextManager): def __init__(self, sock: Channel) -> None: ... @classmethod def from_transport( - cls, t: Transport, window_size: int | None = ..., max_packet_size: int | None = ... - ) -> SFTPClient | None: ... + cls: type[Self], t: Transport, window_size: int | None = ..., max_packet_size: int | None = ... + ) -> Self | None: ... def close(self) -> None: ... def get_channel(self) -> Channel | None: ... def listdir(self, path: str = ...) -> list[str]: ...