Skip to content

Commit 4c94f8d

Browse files
committed
[docker-py] Add some missing types
- `Container` - `ContainerCollection` - `ExecApiMixin`
1 parent 1218f18 commit 4c94f8d

File tree

2 files changed

+94
-24
lines changed

2 files changed

+94
-24
lines changed
Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
from _io import _BufferedReaderStream
2+
from _typeshed import Incomplete
3+
from socket import SocketIO
4+
from typing import Literal, overload
5+
6+
from docker.transport.sshconn import SSHSocket
7+
from docker.types.daemon import CancellableStream
8+
19
class ExecApiMixin:
210
def exec_create(
311
self,
@@ -9,12 +17,69 @@ class ExecApiMixin:
917
tty: bool = False,
1018
privileged: bool = False,
1119
user: str = "",
12-
environment=None,
13-
workdir=None,
14-
detach_keys=None,
15-
): ...
16-
def exec_inspect(self, exec_id): ...
17-
def exec_resize(self, exec_id, height=None, width=None) -> None: ...
20+
environment: dict[str, str] | list[str] | None = None,
21+
workdir: str | None = None,
22+
detach_keys: str | None = None,
23+
) -> dict[str, Incomplete]: ...
24+
def exec_inspect(self, exec_id: str) -> dict[str, Incomplete]: ...
25+
def exec_resize(self, exec_id: str, height: int | None = None, width: int | None = None) -> None: ...
26+
@overload
1827
def exec_start(
19-
self, exec_id, detach: bool = False, tty: bool = False, stream: bool = False, socket: bool = False, demux: bool = False
20-
): ...
28+
self,
29+
exec_id: str,
30+
detach: Literal[True] = ...,
31+
tty: bool = False,
32+
stream: bool = False,
33+
socket: bool = False,
34+
demux: bool = False,
35+
) -> str: ...
36+
@overload
37+
def exec_start(
38+
self,
39+
exec_id: str,
40+
detach: Literal[False] = False,
41+
tty: bool = False,
42+
stream: bool = False,
43+
socket: Literal[True] = ...,
44+
demux: bool = False,
45+
) -> SocketIO | _BufferedReaderStream | SSHSocket: ...
46+
@overload
47+
def exec_start(
48+
self,
49+
exec_id: str,
50+
detach: Literal[False] = False,
51+
tty: bool = False,
52+
stream: Literal[True] = ...,
53+
socket: Literal[False] = False,
54+
demux: Literal[True] = ...,
55+
) -> CancellableStream[tuple[str | None, str | None]]: ...
56+
@overload
57+
def exec_start(
58+
self,
59+
exec_id: str,
60+
detach: bool = False,
61+
tty: bool = False,
62+
stream: Literal[True] = ...,
63+
socket: bool = False,
64+
demux: bool = False,
65+
) -> CancellableStream[str]: ...
66+
@overload
67+
def exec_start(
68+
self,
69+
exec_id: str,
70+
detach: bool = False,
71+
tty: bool = False,
72+
stream: bool = False,
73+
socket: bool = False,
74+
demux: Literal[True] = ...,
75+
) -> tuple[str | None, str | None]: ...
76+
@overload
77+
def exec_start(
78+
self,
79+
exec_id: str,
80+
detach: bool = False,
81+
tty: bool = False,
82+
stream: bool = False,
83+
socket: bool = False,
84+
demux: bool = False,
85+
) -> str: ...

stubs/docker/docker/models/containers.pyi

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import datetime
2+
from _io import _BufferedReaderStream
23
from _typeshed import Incomplete
3-
from collections.abc import Iterable, Mapping
4+
from collections.abc import Iterable, Iterator, Mapping
5+
from socket import SocketIO
46
from typing import Literal, NamedTuple, TypedDict, overload, type_check_only
57
from typing_extensions import NotRequired
68

79
from docker._types import ContainerWeightDevice, WaitContainerResponse
10+
from docker.transport.sshconn import SSHSocket
811
from docker.types import EndpointConfig
912
from docker.types.containers import DeviceRequest, LogConfig, Ulimit
1013
from docker.types.daemon import CancellableStream
@@ -36,10 +39,12 @@ class Container(Model):
3639
def health(self) -> str: ...
3740
@property
3841
def ports(self) -> dict[Incomplete, Incomplete]: ...
39-
def attach(self, **kwargs): ...
40-
def attach_socket(self, **kwargs): ...
41-
def commit(self, repository: str | None = None, tag: str | None = None, **kwargs): ...
42-
def diff(self): ...
42+
def attach(
43+
self, **kwargs
44+
) -> str | tuple[str | None, str | None] | CancellableStream[str] | CancellableStream[tuple[str | None, str | None]]: ...
45+
def attach_socket(self, **kwargs) -> SocketIO | _BufferedReaderStream | SSHSocket: ...
46+
def commit(self, repository: str | None = None, tag: str | None = None, **kwargs) -> Image: ...
47+
def diff(self) -> list[dict[str, Incomplete]]: ...
4348
def exec_run(
4449
self,
4550
cmd: str | list[str],
@@ -52,15 +57,15 @@ class Container(Model):
5257
detach: bool = False,
5358
stream: bool = False,
5459
socket: bool = False,
55-
environment=None,
56-
workdir=None,
60+
environment: dict[str, str] | list[str] | None = None,
61+
workdir: str | None = None,
5762
demux: bool = False,
5863
) -> ExecResult: ...
5964
def export(self, chunk_size: int | None = 2097152) -> str: ...
6065
def get_archive(
6166
self, path: str, chunk_size: int | None = 2097152, encode_stream: bool = False
6267
) -> tuple[Incomplete, Incomplete]: ...
63-
def kill(self, signal=None): ...
68+
def kill(self, signal: str | int | None = None) -> None: ...
6469
@overload
6570
def logs(
6671
self,
@@ -90,14 +95,14 @@ class Container(Model):
9095
def pause(self) -> None: ...
9196
def put_archive(self, path: str, data) -> bool: ...
9297
def remove(self, *, v: bool = False, link: bool = False, force: bool = False) -> None: ...
93-
def rename(self, name: str): ...
94-
def resize(self, height: int, width: int): ...
95-
def restart(self, *, timeout: float | None = 10): ...
98+
def rename(self, name: str) -> None: ...
99+
def resize(self, height: int, width: int) -> None: ...
100+
def restart(self, *, timeout: float | None = 10) -> None: ...
96101
def start(self) -> None: ...
97-
def stats(self, **kwargs): ...
102+
def stats(self, **kwargs) -> Iterator[dict[str, Incomplete]] | dict[str, Incomplete]: ...
98103
def stop(self, *, timeout: float | None = None) -> None: ...
99104
def top(self, *, ps_args: str | None = None) -> _TopResult: ...
100-
def unpause(self): ...
105+
def unpause(self) -> None: ...
101106
def update(
102107
self,
103108
*,
@@ -405,13 +410,13 @@ class ContainerCollection(Collection[Container]):
405410
self,
406411
all: bool = False,
407412
before: str | None = None,
408-
filters=None,
413+
filters: dict[str, Incomplete] | None = None,
409414
limit: int = -1,
410415
since: str | None = None,
411416
sparse: bool = False,
412417
ignore_removed: bool = False,
413-
): ...
414-
def prune(self, filters=None): ...
418+
) -> list[Container]: ...
419+
def prune(self, filters: dict[str, Incomplete] | None = None) -> dict[str, Incomplete]: ...
415420

416421
RUN_CREATE_KWARGS: list[str]
417422
RUN_HOST_CONFIG_KWARGS: list[str]

0 commit comments

Comments
 (0)