Skip to content

[paramiko] Add missing stubs #14363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions stubs/paramiko/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
paramiko.SFTPServer.__init__
paramiko.sftp_server.SFTPServer.__init__
paramiko.util.SupportsClose
1 change: 1 addition & 0 deletions stubs/paramiko/@tests/stubtest_allowlist_darwin.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
paramiko._winapi
paramiko.win_openssh.*
paramiko.win_pageant
1 change: 1 addition & 0 deletions stubs/paramiko/@tests/stubtest_allowlist_linux.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
paramiko._winapi
paramiko.win_openssh.*
paramiko.win_pageant
2 changes: 0 additions & 2 deletions stubs/paramiko/METADATA.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ version = "3.5.*"
upstream_repository = "https://github.com/paramiko/paramiko"
# Requires a version of cryptography where cryptography.hazmat.primitives.ciphers.Cipher is generic
requires = ["cryptography>=37.0.0"]
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
# linux and darwin are equivalent
platforms = ["linux", "win32"]
48 changes: 45 additions & 3 deletions stubs/paramiko/paramiko/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from paramiko import util as util
from paramiko.agent import Agent as Agent, AgentKey as AgentKey
from paramiko.channel import Channel as Channel, ChannelFile as ChannelFile
from paramiko.client import (
Expand Down Expand Up @@ -41,6 +42,47 @@ from paramiko.transport import SecurityOptions as SecurityOptions, Transport as

__author__: str
__license__: str

# Names in __all__ with no definition:
# util
__all__ = [
"Agent",
"AgentKey",
"AuthenticationException",
"AutoAddPolicy",
"BadAuthenticationType",
"BadHostKeyException",
"BufferedFile",
"Channel",
"ChannelException",
"ConfigParseError",
"CouldNotCanonicalize",
"DSSKey",
"ECDSAKey",
"Ed25519Key",
"HostKeys",
"Message",
"MissingHostKeyPolicy",
"PKey",
"PasswordRequiredException",
"ProxyCommand",
"ProxyCommandFailure",
"RSAKey",
"RejectPolicy",
"SFTP",
"SFTPAttributes",
"SFTPClient",
"SFTPError",
"SFTPFile",
"SFTPHandle",
"SFTPServer",
"SFTPServerInterface",
"SSHClient",
"SSHConfig",
"SSHConfigDict",
"SSHException",
"SecurityOptions",
"ServerInterface",
"SubsystemHandler",
"Transport",
"WarningPolicy",
"io_sleep",
"util",
]
41 changes: 25 additions & 16 deletions stubs/paramiko/paramiko/_winapi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import ctypes
import sys
from _typeshed import Incomplete
from types import TracebackType
from typing import Any
from typing_extensions import Self

if sys.platform == "win32":
Expand All @@ -18,14 +17,14 @@ if sys.platform == "win32":

def handle_nonzero_success(result: int) -> None: ...
GMEM_MOVEABLE: int
GlobalAlloc: Any
GlobalLock: Any
GlobalUnlock: Any
GlobalSize: Any
CreateFileMapping: Any
MapViewOfFile: Any
UnmapViewOfFile: Any
RtlMoveMemory: Any
GlobalAlloc: Incomplete
GlobalLock: Incomplete
GlobalUnlock: Incomplete
GlobalSize: Incomplete
CreateFileMapping: Incomplete
MapViewOfFile: Incomplete
UnmapViewOfFile: Incomplete
RtlMoveMemory: Incomplete

class MemoryMap:
name: str
Expand Down Expand Up @@ -75,21 +74,31 @@ if sys.platform == "win32":

class TOKEN_USER(ctypes.Structure):
num: int
SID: Incomplete
ATTRIBUTES: Incomplete

class SECURITY_DESCRIPTOR(ctypes.Structure):
SECURITY_DESCRIPTOR_CONTROL: Any
SECURITY_DESCRIPTOR_CONTROL: Incomplete
REVISION: int
Revision: int
Sbz1: Incomplete
Control: Incomplete
Owner: Incomplete
Group: Incomplete
Sacl: Incomplete
Dacl: Incomplete

class SECURITY_ATTRIBUTES(ctypes.Structure):
nLength: int
lpSecurityDescriptor: Any
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
lpSecurityDescriptor: int
bInheritHandle: bool
def __init__(self, *args, **kwargs) -> None: ...
@property
def descriptor(self) -> Any: ...
def descriptor(self): ...
@descriptor.setter
def descriptor(self, value: Any) -> None: ...
def descriptor(self, value) -> None: ...

def GetTokenInformation(token: Any, information_class: Any) -> Any: ...
def OpenProcessToken(proc_handle: Any, access: Any) -> Any: ...
def GetTokenInformation(token, information_class): ...
def OpenProcessToken(proc_handle, access): ...
def get_current_user() -> TOKEN_USER: ...
def get_security_attributes_for_user(user: TOKEN_USER | None = None) -> SECURITY_ATTRIBUTES: ...
38 changes: 33 additions & 5 deletions stubs/paramiko/paramiko/agent.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import sys
from _typeshed import ReadableBuffer
from collections.abc import Mapping
from logging import _ExcInfoType
from socket import _RetAddress, socket
from threading import Thread
from typing import Protocol
from typing import Final, Protocol

from paramiko.channel import Channel
from paramiko.message import Message, _LikeBytes
Expand All @@ -12,10 +15,16 @@ class _AgentProxy(Protocol):
def connect(self) -> None: ...
def close(self) -> None: ...

cSSH2_AGENTC_REQUEST_IDENTITIES: bytes
SSH2_AGENT_IDENTITIES_ANSWER: int
cSSH2_AGENTC_SIGN_REQUEST: bytes
SSH2_AGENT_SIGN_RESPONSE: int
cSSH2_AGENTC_REQUEST_IDENTITIES: Final[bytes]
SSH2_AGENT_IDENTITIES_ANSWER: Final = 12
cSSH2_AGENTC_SIGN_REQUEST: Final[bytes]
SSH2_AGENT_SIGN_RESPONSE: Final = 14

SSH_AGENT_RSA_SHA2_256: Final = 2
SSH_AGENT_RSA_SHA2_512: Final = 4
ALGORITHM_FLAG_MAP: Final[dict[str, int]]
key: str
value: int

class AgentSSH:
def __init__(self) -> None: ...
Expand All @@ -33,6 +42,15 @@ class AgentRemoteProxy(AgentProxyThread):
def __init__(self, agent: AgentClientProxy, chan: Channel) -> None: ...
def get_connection(self) -> tuple[socket, _RetAddress]: ...

if sys.platform == "win32":
from .win_openssh import OpenSSHAgentConnection
from .win_pageant import PageantConnection

def get_agent_connection() -> PageantConnection | OpenSSHAgentConnection | None: ...

else:
def get_agent_connection() -> socket | None: ...

class AgentClientProxy:
thread: Thread
def __init__(self, chanRemote: Channel) -> None: ...
Expand Down Expand Up @@ -64,6 +82,16 @@ class AgentKey(PKey):
name: str
comment: str
def __init__(self, agent: AgentSSH, blob: ReadableBuffer, comment: str = "") -> None: ...
def log(
self,
level: int,
msg: object,
*args: object,
exc_info: _ExcInfoType = None,
stack_info: bool = False,
stacklevel: int = 1,
extra: Mapping[str, object] | None = None,
) -> None: ...
def asbytes(self) -> bytes: ...
def get_name(self) -> str: ...
def sign_ssh_data(self, data: _LikeBytes, algorithm: str | None = None) -> Message: ...
10 changes: 10 additions & 0 deletions stubs/paramiko/paramiko/auth_handler.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ from collections.abc import Callable
from threading import Event
from typing_extensions import TypeAlias

from paramiko.message import Message
from paramiko.pkey import PKey
from paramiko.ssh_gss import _SSH_GSSAuth
from paramiko.transport import Transport
Expand Down Expand Up @@ -46,3 +47,12 @@ class GssapiWithMicAuthHandler:
def auth_username(self) -> str: ...
@property
def gss_host(self) -> str: ...

class AuthOnlyHandler(AuthHandler):
def send_auth_request(
self, username: str, method: str, finish_message: Callable[[Message], None] | None = None
) -> list[str]: ...
def auth_none(self, username: str) -> list[str]: ... # type: ignore[override]
def auth_publickey(self, username: str, key: PKey) -> list[str]: ... # type: ignore[override]
def auth_password(self, username: str, password: str) -> list[str]: ... # type: ignore[override]
def auth_interactive(self, username: str, handler: _InteractiveCallback, submethods: str = "") -> list[str]: ... # type: ignore[override]
Loading