Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
81 changes: 73 additions & 8 deletions stubs/docker/docker/api/exec_api.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
from _io import _BufferedReaderStream
from _typeshed import Incomplete
from socket import SocketIO
from typing import Literal, overload

from docker.transport.sshconn import SSHSocket
from docker.types.daemon import CancellableStream

class ExecApiMixin:
def exec_create(
self,
Expand All @@ -9,12 +17,69 @@ class ExecApiMixin:
tty: bool = False,
privileged: bool = False,
user: str = "",
environment=None,
workdir=None,
detach_keys=None,
): ...
def exec_inspect(self, exec_id): ...
def exec_resize(self, exec_id, height=None, width=None) -> None: ...
environment: dict[str, str] | list[str] | None = None,
workdir: str | None = None,
detach_keys: str | None = None,
) -> dict[str, Incomplete]: ...
def exec_inspect(self, exec_id: str) -> dict[str, Incomplete]: ...
def exec_resize(self, exec_id: str, height: int | None = None, width: int | None = None) -> None: ...
@overload
def exec_start(
self, exec_id, detach: bool = False, tty: bool = False, stream: bool = False, socket: bool = False, demux: bool = False
): ...
self,
exec_id: str,
detach: Literal[True] = ...,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wouldn't work, since it would also match if detach is left out (meaning it's False):

Suggested change
detach: Literal[True] = ...,
detach: Literal[True],

tty: bool = False,
stream: bool = False,
socket: bool = False,
demux: bool = False,
) -> str: ...
@overload
def exec_start(
self,
exec_id: str,
detach: Literal[False] = False,
tty: bool = False,
stream: bool = False,
socket: Literal[True] = ...,
demux: bool = False,
) -> SocketIO | _BufferedReaderStream | SSHSocket: ...
Comment on lines 36 to 50
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same is true for the socket argument here. Unfortunately, we can't just remove the default as that would cause a syntax error. So we can to split this overload into two:

Suggested change
@overload
def exec_start(
self,
exec_id: str,
detach: Literal[False] = False,
tty: bool = False,
stream: bool = False,
socket: Literal[True] = ...,
demux: bool = False,
) -> SocketIO | _BufferedReaderStream | SSHSocket: ...
@overload
def exec_start(
self,
exec_id: str,
detach: Literal[False],
tty: bool,
stream: bool,
socket: Literal[True],
demux: bool = False,
) -> SocketIO | _BufferedReaderStream | SSHSocket: ...
@overload
def exec_start(
self,
exec_id: str,
detach: Literal[False] = False,
tty: bool = False,
stream: bool = False,
*,
socket: Literal[True],
demux: bool = False,
) -> SocketIO | _BufferedReaderStream | SSHSocket: ...

The same for the other overloads using a ... default below. I won't be pretty.

@overload
def exec_start(
self,
exec_id: str,
detach: Literal[False] = False,
tty: bool = False,
stream: Literal[True] = ...,
socket: Literal[False] = False,
demux: Literal[True] = ...,
) -> CancellableStream[tuple[str | None, str | None]]: ...
@overload
def exec_start(
self,
exec_id: str,
detach: bool = False,
tty: bool = False,
stream: Literal[True] = ...,
socket: bool = False,
demux: bool = False,
) -> CancellableStream[str]: ...
@overload
def exec_start(
self,
exec_id: str,
detach: bool = False,
tty: bool = False,
stream: bool = False,
socket: bool = False,
demux: Literal[True] = ...,
) -> tuple[str | None, str | None]: ...
@overload
def exec_start(
self,
exec_id: str,
detach: bool = False,
tty: bool = False,
stream: bool = False,
socket: bool = False,
demux: bool = False,
) -> str: ...
37 changes: 21 additions & 16 deletions stubs/docker/docker/models/containers.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import datetime
from _io import _BufferedReaderStream
from _typeshed import Incomplete
from collections.abc import Iterable, Mapping
from collections.abc import Iterable, Iterator, Mapping
from socket import SocketIO
from typing import Literal, NamedTuple, TypedDict, overload, type_check_only
from typing_extensions import NotRequired

from docker._types import ContainerWeightDevice, WaitContainerResponse
from docker.transport.sshconn import SSHSocket
from docker.types import EndpointConfig
from docker.types.containers import DeviceRequest, LogConfig, Ulimit
from docker.types.daemon import CancellableStream
Expand Down Expand Up @@ -36,10 +39,12 @@ class Container(Model):
def health(self) -> str: ...
@property
def ports(self) -> dict[Incomplete, Incomplete]: ...
def attach(self, **kwargs): ...
def attach_socket(self, **kwargs): ...
def commit(self, repository: str | None = None, tag: str | None = None, **kwargs): ...
def diff(self): ...
def attach(
self, **kwargs
) -> str | tuple[str | None, str | None] | CancellableStream[str] | CancellableStream[tuple[str | None, str | None]]: ...
def attach_socket(self, **kwargs) -> SocketIO | _BufferedReaderStream | SSHSocket: ...
def commit(self, repository: str | None = None, tag: str | None = None, **kwargs) -> Image: ...
def diff(self) -> list[dict[str, Incomplete]]: ...
def exec_run(
self,
cmd: str | list[str],
Expand All @@ -52,15 +57,15 @@ class Container(Model):
detach: bool = False,
stream: bool = False,
socket: bool = False,
environment=None,
workdir=None,
environment: dict[str, str] | list[str] | None = None,
workdir: str | None = None,
demux: bool = False,
) -> ExecResult: ...
def export(self, chunk_size: int | None = 2097152) -> str: ...
def get_archive(
self, path: str, chunk_size: int | None = 2097152, encode_stream: bool = False
) -> tuple[Incomplete, Incomplete]: ...
def kill(self, signal=None): ...
def kill(self, signal: str | int | None = None) -> None: ...
@overload
def logs(
self,
Expand Down Expand Up @@ -90,14 +95,14 @@ class Container(Model):
def pause(self) -> None: ...
def put_archive(self, path: str, data) -> bool: ...
def remove(self, *, v: bool = False, link: bool = False, force: bool = False) -> None: ...
def rename(self, name: str): ...
def resize(self, height: int, width: int): ...
def restart(self, *, timeout: float | None = 10): ...
def rename(self, name: str) -> None: ...
def resize(self, height: int, width: int) -> None: ...
def restart(self, *, timeout: float | None = 10) -> None: ...
def start(self) -> None: ...
def stats(self, **kwargs): ...
def stats(self, **kwargs) -> Iterator[dict[str, Incomplete]] | dict[str, Incomplete]: ...
def stop(self, *, timeout: float | None = None) -> None: ...
def top(self, *, ps_args: str | None = None) -> _TopResult: ...
def unpause(self): ...
def unpause(self) -> None: ...
def update(
self,
*,
Expand Down Expand Up @@ -405,13 +410,13 @@ class ContainerCollection(Collection[Container]):
self,
all: bool = False,
before: str | None = None,
filters=None,
filters: dict[str, Incomplete] | None = None,
limit: int = -1,
since: str | None = None,
sparse: bool = False,
ignore_removed: bool = False,
): ...
def prune(self, filters=None): ...
) -> list[Container]: ...
def prune(self, filters: dict[str, Incomplete] | None = None) -> dict[str, Incomplete]: ...

RUN_CREATE_KWARGS: list[str]
RUN_HOST_CONFIG_KWARGS: list[str]
Expand Down