From 262f2067aad0d34886e6f16d1a1cd6c82edf1209 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 6 Feb 2023 15:01:50 +0000 Subject: [PATCH] Update `paramiko` stubs to 3.0.* (#9667) --- stubs/paramiko/@tests/stubtest_allowlist.txt | 5 ---- stubs/paramiko/METADATA.toml | 2 +- stubs/paramiko/paramiko/common.pyi | 13 ++------ stubs/paramiko/paramiko/config.pyi | 3 +- stubs/paramiko/paramiko/message.pyi | 9 ++++-- stubs/paramiko/paramiko/pkey.pyi | 2 +- stubs/paramiko/paramiko/py3compat.pyi | 31 -------------------- stubs/paramiko/paramiko/util.pyi | 16 +++++----- 8 files changed, 20 insertions(+), 61 deletions(-) delete mode 100644 stubs/paramiko/paramiko/py3compat.pyi diff --git a/stubs/paramiko/@tests/stubtest_allowlist.txt b/stubs/paramiko/@tests/stubtest_allowlist.txt index 39218dcb2..930b0e7fb 100644 --- a/stubs/paramiko/@tests/stubtest_allowlist.txt +++ b/stubs/paramiko/@tests/stubtest_allowlist.txt @@ -2,11 +2,6 @@ paramiko.SFTPServer.__init__ paramiko.Transport.open_x11_channel paramiko.Transport.send_ignore paramiko.Transport.start_server -paramiko.py3compat.input -paramiko.py3compat.BytesIO.readlines -paramiko.py3compat.BytesIO.seek -paramiko.py3compat.StringIO.seek -paramiko.py3compat.StringIO.truncate paramiko.sftp_server.SFTPServer.__init__ paramiko.transport.Transport.open_x11_channel paramiko.transport.Transport.send_ignore diff --git a/stubs/paramiko/METADATA.toml b/stubs/paramiko/METADATA.toml index a1fdb19d0..4080d8ff4 100644 --- a/stubs/paramiko/METADATA.toml +++ b/stubs/paramiko/METADATA.toml @@ -1,4 +1,4 @@ -version = "2.12.*" +version = "3.0.*" # Requires a version of cryptography where cryptography.hazmat.primitives.ciphers.Cipher is generic requires = ["cryptography>=37.0.0"] diff --git a/stubs/paramiko/paramiko/common.pyi b/stubs/paramiko/paramiko/common.pyi index 3900ce064..c895dfd31 100644 --- a/stubs/paramiko/paramiko/common.pyi +++ b/stubs/paramiko/paramiko/common.pyi @@ -1,5 +1,6 @@ -from typing import Protocol -from typing_extensions import TypeAlias +def byte_ord(c: int | str) -> int: ... +def byte_chr(c: int) -> bytes: ... +def byte_mask(c: int, mask: int) -> bytes: ... MSG_DISCONNECT: int MSG_IGNORE: int @@ -101,14 +102,6 @@ linefeed_byte: bytes crlf: bytes cr_byte_value: int linefeed_byte_value: int - -class _SupportsAsBytes(Protocol): - def asbytes(self) -> bytes: ... - -_LikeBytes: TypeAlias = bytes | str | _SupportsAsBytes - -def asbytes(s: _LikeBytes) -> bytes: ... - xffffffff: int x80000000: int o666: int diff --git a/stubs/paramiko/paramiko/config.pyi b/stubs/paramiko/paramiko/config.pyi index 3e100ed56..b0b6078f4 100644 --- a/stubs/paramiko/paramiko/config.pyi +++ b/stubs/paramiko/paramiko/config.pyi @@ -1,7 +1,7 @@ from _typeshed import Self from collections.abc import Iterable from re import Pattern -from typing import IO, Any +from typing import IO from paramiko.ssh_exception import ConfigParseError as ConfigParseError, CouldNotCanonicalize as CouldNotCanonicalize @@ -29,6 +29,5 @@ class LazyFqdn: def __init__(self, config: SSHConfigDict, host: str | None = ...) -> None: ... class SSHConfigDict(dict[str, str]): - def __init__(self, *args: Any, **kwargs: Any) -> None: ... def as_bool(self, key: str) -> bool: ... def as_int(self, key: str) -> int: ... diff --git a/stubs/paramiko/paramiko/message.pyi b/stubs/paramiko/paramiko/message.pyi index 0a69bb806..7314f1e0c 100644 --- a/stubs/paramiko/paramiko/message.pyi +++ b/stubs/paramiko/paramiko/message.pyi @@ -1,14 +1,19 @@ from collections.abc import Iterable from io import BytesIO -from typing import Any +from typing import Any, Protocol +from typing_extensions import TypeAlias -from .common import _LikeBytes +class _SupportsAsBytes(Protocol): + def asbytes(self) -> bytes: ... + +_LikeBytes: TypeAlias = bytes | str | _SupportsAsBytes class Message: big_int: int packet: BytesIO seqno: int # only when packet.Packetizer.read_message() is used def __init__(self, content: bytes | None = ...) -> None: ... + def __bytes__(self) -> bytes: ... def asbytes(self) -> bytes: ... def rewind(self) -> None: ... def get_remainder(self) -> bytes: ... diff --git a/stubs/paramiko/paramiko/pkey.pyi b/stubs/paramiko/paramiko/pkey.pyi index 6dd72d5ff..3d58dc9b0 100644 --- a/stubs/paramiko/paramiko/pkey.pyi +++ b/stubs/paramiko/paramiko/pkey.pyi @@ -14,7 +14,7 @@ class PKey: END_TAG: Pattern[str] def __init__(self, msg: Message | None = ..., data: str | None = ...) -> None: ... def asbytes(self) -> bytes: ... - def __cmp__(self, other: object) -> int: ... + def __bytes__(self) -> bytes: ... def __eq__(self, other: object) -> bool: ... def get_name(self) -> str: ... def get_bits(self) -> int: ... diff --git a/stubs/paramiko/paramiko/py3compat.pyi b/stubs/paramiko/paramiko/py3compat.pyi deleted file mode 100644 index 9f64106ab..000000000 --- a/stubs/paramiko/paramiko/py3compat.pyi +++ /dev/null @@ -1,31 +0,0 @@ -import builtins as builtins -from collections.abc import Iterable, Sequence -from io import BytesIO as BytesIO, StringIO as StringIO -from typing import Any, TypeVar - -_T = TypeVar("_T") - -PY2: bool - -string_types: type[Any] | Sequence[type[Any]] -text_type: type[Any] | Sequence[type[Any]] -bytes_types: type[Any] | Sequence[type[Any]] -integer_types: type[Any] | Sequence[type[Any]] -long = int - -def input(prompt: Any) -> str: ... -def decodebytes(s: bytes) -> bytes: ... -def encodebytes(s: bytes) -> bytes: ... - -bytes = builtins.bytes - -def byte_ord(c: int | str) -> int: ... -def byte_chr(c: int) -> bytes: ... -def byte_mask(c: int, mask: int) -> bytes: ... -def b(s: bytes | str, encoding: str = ...) -> bytes: ... -def u(s: bytes | str, encoding: str = ...) -> str: ... -def b2s(s: bytes | str) -> str: ... -def is_callable(c: Any) -> bool: ... -def next(c: Iterable[_T]) -> _T: ... - -MAXSIZE: int diff --git a/stubs/paramiko/paramiko/util.pyi b/stubs/paramiko/paramiko/util.pyi index 3abe7d399..b8c76612d 100644 --- a/stubs/paramiko/paramiko/util.pyi +++ b/stubs/paramiko/paramiko/util.pyi @@ -1,9 +1,8 @@ from _typeshed import Self -from collections.abc import Callable from hashlib import _Hash from logging import Logger, LogRecord from types import TracebackType -from typing import IO, AnyStr, Protocol, TypeVar +from typing import IO, AnyStr, Protocol from paramiko.config import SSHConfig, SSHConfigDict from paramiko.hostkeys import HostKeys @@ -11,13 +10,7 @@ from paramiko.hostkeys import HostKeys class SupportsClose(Protocol): def close(self) -> None: ... -_T = TypeVar("_T") - def inflate_long(s: bytes, always_positive: bool = ...) -> int: ... - -deflate_zero: int -deflate_ff: int - def deflate_long(n: int, add_sign_padding: bool = ...) -> bytes: ... def format_binary(data: bytes, prefix: str = ...) -> list[str]: ... def format_binary_line(data: bytes) -> str: ... @@ -36,7 +29,6 @@ class PFilter: def filter(self, record: LogRecord) -> bool: ... def get_logger(name: str) -> Logger: ... -def retry_on_signal(function: Callable[[], _T]) -> _T: ... def constant_time_bytes_eq(a: AnyStr, b: AnyStr) -> bool: ... class ClosingContextManager: @@ -46,3 +38,9 @@ class ClosingContextManager: ) -> None: ... def clamp_value(minimum: int, val: int, maximum: int) -> int: ... + +# This function attempts to convert objects to bytes, +# *but* just returns the object unchanged if that was unsuccessful! +def asbytes(s: object) -> object: ... +def b(s: str | bytes, encoding: str = "utf-8") -> bytes: ... +def u(s: str | bytes, encoding: str = "utf-8") -> str: ...