Skip to content

Commit e78872c

Browse files
[docker] Fix incomplete types in models and add missing method (#15565)
1 parent 9840d38 commit e78872c

File tree

3 files changed

+64
-46
lines changed

3 files changed

+64
-46
lines changed

stubs/docker/docker/models/containers.pyi

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import datetime
22
from _io import _BufferedReaderStream
3-
from _typeshed import Incomplete
43
from collections.abc import Iterable, Iterator, Mapping
54
from socket import SocketIO
6-
from typing import Literal, NamedTuple, TypedDict, overload, type_check_only
7-
from typing_extensions import NotRequired
5+
from typing import Any, Literal, NamedTuple, TypedDict, overload, type_check_only
6+
from typing_extensions import NotRequired, override
87

98
from docker._types import ContainerWeightDevice, WaitContainerResponse
109
from docker.transport.sshconn import SSHSocket
@@ -38,7 +37,7 @@ class Container(Model):
3837
@property
3938
def health(self) -> str: ...
4039
@property
41-
def ports(self) -> dict[Incomplete, Incomplete]: ...
40+
def ports(self) -> dict[str, list[dict[str, str]] | None]: ...
4241
@overload
4342
def attach(
4443
self,
@@ -75,7 +74,7 @@ class Container(Model):
7574
) -> CancellableStream[tuple[bytes | None, bytes | None]]: ...
7675
def attach_socket(self, **kwargs) -> SocketIO | _BufferedReaderStream | SSHSocket: ...
7776
def commit(self, repository: str | None = None, tag: str | None = None, **kwargs) -> Image: ...
78-
def diff(self) -> list[dict[str, Incomplete]]: ...
77+
def diff(self) -> list[dict[str, int | str]]: ...
7978
def exec_run(
8079
self,
8180
cmd: str | list[str],
@@ -95,7 +94,7 @@ class Container(Model):
9594
def export(self, chunk_size: int | None = 2097152) -> str: ...
9695
def get_archive(
9796
self, path: str, chunk_size: int | None = 2097152, encode_stream: bool = False
98-
) -> tuple[Incomplete, Incomplete]: ...
97+
) -> tuple[Iterator[bytes], dict[str, Any] | None]: ...
9998
def kill(self, signal: str | int | None = None) -> None: ...
10099
@overload
101100
def logs(
@@ -130,7 +129,7 @@ class Container(Model):
130129
def resize(self, height: int, width: int) -> None: ...
131130
def restart(self, *, timeout: float | None = 10) -> None: ...
132131
def start(self) -> None: ...
133-
def stats(self, **kwargs) -> Iterator[dict[str, Incomplete]] | dict[str, Incomplete]: ...
132+
def stats(self, **kwargs) -> Iterator[dict[str, Any]] | dict[str, Any]: ...
134133
def stop(self, *, timeout: float | None = None) -> None: ...
135134
def top(self, *, ps_args: str | None = None) -> _TopResult: ...
136135
def unpause(self) -> None: ...
@@ -181,22 +180,22 @@ class ContainerCollection(Collection[Container]):
181180
cpuset_cpus: str | None = None,
182181
cpuset_mems: str | None = None,
183182
detach: Literal[False] = False,
184-
device_cgroup_rules: list[Incomplete] | None = None,
183+
device_cgroup_rules: list[str] | None = None,
185184
device_read_bps: list[Mapping[str, str | int]] | None = None,
186185
device_read_iops: list[Mapping[str, str | int]] | None = None,
187186
device_write_bps: list[Mapping[str, str | int]] | None = None,
188187
device_write_iops: list[Mapping[str, str | int]] | None = None,
189188
devices: list[str] | None = None,
190189
device_requests: list[DeviceRequest] | None = None,
191-
dns: list[Incomplete] | None = None,
192-
dns_opt: list[Incomplete] | None = None,
193-
dns_search: list[Incomplete] | None = None,
194-
domainname: str | list[Incomplete] | None = None,
190+
dns: list[str] | None = None,
191+
dns_opt: list[str] | None = None,
192+
dns_search: list[str] | None = None,
193+
domainname: str | list[str] | None = None,
195194
entrypoint: str | list[str] | None = None,
196195
environment: dict[str, str] | list[str] | None = None,
197196
extra_hosts: dict[str, str] | None = None,
198197
group_add: Iterable[str | int] | None = None,
199-
healthcheck: dict[Incomplete, Incomplete] | None = None,
198+
healthcheck: dict[str, Any] | None = None,
200199
hostname: str | None = None,
201200
init: bool | None = None,
202201
init_path: str | None = None,
@@ -206,7 +205,7 @@ class ContainerCollection(Collection[Container]):
206205
labels: dict[str, str] | list[str] | None = None,
207206
links: dict[str, str] | dict[str, None] | dict[str, str | None] | Iterable[tuple[str, str | None]] | None = None,
208207
log_config: LogConfig | None = None,
209-
lxc_conf: dict[Incomplete, Incomplete] | None = None,
208+
lxc_conf: dict[str, str] | None = None,
210209
mac_address: str | None = None,
211210
mem_limit: str | int | None = None,
212211
mem_reservation: str | int | None = None,
@@ -234,9 +233,9 @@ class ContainerCollection(Collection[Container]):
234233
shm_size: str | int | None = None,
235234
stdin_open: bool = False,
236235
stop_signal: str | None = None,
237-
storage_opt: dict[Incomplete, Incomplete] | None = None,
236+
storage_opt: dict[str, str] | None = None,
238237
stream: bool = False,
239-
sysctls: dict[Incomplete, Incomplete] | None = None,
238+
sysctls: dict[str, str] | None = None,
240239
tmpfs: dict[str, str] | None = None,
241240
tty: bool = False,
242241
ulimits: list[Ulimit] | None = None,
@@ -276,22 +275,22 @@ class ContainerCollection(Collection[Container]):
276275
cpuset_cpus: str | None = None,
277276
cpuset_mems: str | None = None,
278277
detach: Literal[True],
279-
device_cgroup_rules: list[Incomplete] | None = None,
278+
device_cgroup_rules: list[str] | None = None,
280279
device_read_bps: list[Mapping[str, str | int]] | None = None,
281280
device_read_iops: list[Mapping[str, str | int]] | None = None,
282281
device_write_bps: list[Mapping[str, str | int]] | None = None,
283282
device_write_iops: list[Mapping[str, str | int]] | None = None,
284283
devices: list[str] | None = None,
285284
device_requests: list[DeviceRequest] | None = None,
286-
dns: list[Incomplete] | None = None,
287-
dns_opt: list[Incomplete] | None = None,
288-
dns_search: list[Incomplete] | None = None,
289-
domainname: str | list[Incomplete] | None = None,
285+
dns: list[str] | None = None,
286+
dns_opt: list[str] | None = None,
287+
dns_search: list[str] | None = None,
288+
domainname: str | list[str] | None = None,
290289
entrypoint: str | list[str] | None = None,
291290
environment: dict[str, str] | list[str] | None = None,
292291
extra_hosts: dict[str, str] | None = None,
293292
group_add: Iterable[str | int] | None = None,
294-
healthcheck: dict[Incomplete, Incomplete] | None = None,
293+
healthcheck: dict[str, Any] | None = None,
295294
hostname: str | None = None,
296295
init: bool | None = None,
297296
init_path: str | None = None,
@@ -301,7 +300,7 @@ class ContainerCollection(Collection[Container]):
301300
labels: dict[str, str] | list[str] | None = None,
302301
links: dict[str, str] | dict[str, None] | dict[str, str | None] | Iterable[tuple[str, str | None]] | None = None,
303302
log_config: LogConfig | None = None,
304-
lxc_conf: dict[Incomplete, Incomplete] | None = None,
303+
lxc_conf: dict[str, str] | None = None,
305304
mac_address: str | None = None,
306305
mem_limit: str | int | None = None,
307306
mem_reservation: str | int | None = None,
@@ -329,9 +328,9 @@ class ContainerCollection(Collection[Container]):
329328
shm_size: str | int | None = None,
330329
stdin_open: bool = False,
331330
stop_signal: str | None = None,
332-
storage_opt: dict[Incomplete, Incomplete] | None = None,
331+
storage_opt: dict[str, str] | None = None,
333332
stream: bool = False,
334-
sysctls: dict[Incomplete, Incomplete] | None = None,
333+
sysctls: dict[str, str] | None = None,
335334
tmpfs: dict[str, str] | None = None,
336335
tty: bool = False,
337336
ulimits: list[Ulimit] | None = None,
@@ -345,6 +344,7 @@ class ContainerCollection(Collection[Container]):
345344
volumes_from: list[str] | None = None,
346345
working_dir: str | None = None,
347346
) -> Container: ...
347+
@override
348348
def create( # type:ignore[override]
349349
self,
350350
image: str | Image,
@@ -367,22 +367,22 @@ class ContainerCollection(Collection[Container]):
367367
cpuset_cpus: str | None = None,
368368
cpuset_mems: str | None = None,
369369
detach: bool = False,
370-
device_cgroup_rules: list[Incomplete] | None = None,
370+
device_cgroup_rules: list[str] | None = None,
371371
device_read_bps: list[Mapping[str, str | int]] | None = None,
372372
device_read_iops: list[Mapping[str, str | int]] | None = None,
373373
device_write_bps: list[Mapping[str, str | int]] | None = None,
374374
device_write_iops: list[Mapping[str, str | int]] | None = None,
375375
devices: list[str] | None = None,
376376
device_requests: list[DeviceRequest] | None = None,
377-
dns: list[Incomplete] | None = None,
378-
dns_opt: list[Incomplete] | None = None,
379-
dns_search: list[Incomplete] | None = None,
380-
domainname: str | list[Incomplete] | None = None,
377+
dns: list[str] | None = None,
378+
dns_opt: list[str] | None = None,
379+
dns_search: list[str] | None = None,
380+
domainname: str | list[str] | None = None,
381381
entrypoint: str | list[str] | None = None,
382382
environment: dict[str, str] | list[str] | None = None,
383383
extra_hosts: dict[str, str] | None = None,
384384
group_add: Iterable[str | int] | None = None,
385-
healthcheck: dict[Incomplete, Incomplete] | None = None,
385+
healthcheck: dict[str, Any] | None = None,
386386
hostname: str | None = None,
387387
init: bool | None = None,
388388
init_path: str | None = None,
@@ -392,7 +392,7 @@ class ContainerCollection(Collection[Container]):
392392
labels: dict[str, str] | list[str] | None = None,
393393
links: dict[str, str] | dict[str, None] | dict[str, str | None] | Iterable[tuple[str, str | None]] | None = None,
394394
log_config: LogConfig | None = None,
395-
lxc_conf: dict[Incomplete, Incomplete] | None = None,
395+
lxc_conf: dict[str, str] | None = None,
396396
mac_address: str | None = None,
397397
mem_limit: str | int | None = None,
398398
mem_reservation: str | int | None = None,
@@ -420,9 +420,9 @@ class ContainerCollection(Collection[Container]):
420420
shm_size: str | int | None = None,
421421
stdin_open: bool = False,
422422
stop_signal: str | None = None,
423-
storage_opt: dict[Incomplete, Incomplete] | None = None,
423+
storage_opt: dict[str, str] | None = None,
424424
stream: bool = False,
425-
sysctls: dict[Incomplete, Incomplete] | None = None,
425+
sysctls: dict[str, str] | None = None,
426426
tmpfs: dict[str, str] | None = None,
427427
tty: bool = False,
428428
ulimits: list[Ulimit] | None = None,
@@ -436,22 +436,23 @@ class ContainerCollection(Collection[Container]):
436436
volumes_from: list[str] | None = None,
437437
working_dir: str | None = None,
438438
) -> Container: ...
439+
@override
439440
def get(self, container_id: str) -> Container: ...
440441
def list(
441442
self,
442443
all: bool = False,
443444
before: str | None = None,
444-
filters: dict[str, Incomplete] | None = None,
445+
filters: dict[str, str | list[str] | bool] | None = None,
445446
limit: int = -1,
446447
since: str | None = None,
447448
sparse: bool = False,
448449
ignore_removed: bool = False,
449450
) -> list[Container]: ...
450-
def prune(self, filters: dict[str, Incomplete] | None = None) -> dict[str, Incomplete]: ...
451+
def prune(self, filters: dict[str, Any] | None = None) -> dict[str, Any]: ...
451452

452453
RUN_CREATE_KWARGS: list[str]
453454
RUN_HOST_CONFIG_KWARGS: list[str]
454455

455456
class ExecResult(NamedTuple):
456-
exit_code: Incomplete
457-
output: Incomplete
457+
exit_code: int | None
458+
output: bytes | Iterator[bytes]
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
1-
from _typeshed import Incomplete
21
from collections.abc import Generator
2+
from typing import Any
3+
from typing_extensions import override
34

45
from .resource import Collection, Model
56

67
class Plugin(Model):
78
@property
8-
def name(self): ...
9+
def name(self) -> str | None: ...
910
@property
10-
def enabled(self): ...
11+
def enabled(self) -> bool | None: ...
1112
@property
12-
def settings(self): ...
13-
def configure(self, options) -> None: ...
13+
def settings(self) -> dict[str, Any] | None: ...
14+
def configure(self, options: dict[str, Any]) -> None: ...
1415
def disable(self, force: bool = False) -> None: ...
1516
def enable(self, timeout: int = 0) -> None: ...
16-
def push(self): ...
17-
def remove(self, force: bool = False): ...
18-
def upgrade(self, remote=None) -> Generator[Incomplete, Incomplete, None]: ...
17+
def push(self) -> Generator[dict[str, Any], None, None]: ...
18+
def remove(self, force: bool = False) -> bool: ...
19+
def upgrade(self, remote: str | None = None) -> Generator[dict[str, Any], None, None]: ...
1920

2021
class PluginCollection(Collection[Plugin]):
2122
model: type[Plugin]
23+
@override
2224
def create(self, name, plugin_data_dir, gzip: bool = False): ... # type:ignore[override]
25+
@override
2326
def get(self, name): ...
2427
def install(self, remote_name, local_name=None): ...
28+
@override
2529
def list(self): ...
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1+
from collections.abc import Mapping
2+
from typing_extensions import override
3+
14
import requests.adapters
5+
from urllib3.connectionpool import ConnectionPool
26

37
class BaseHTTPAdapter(requests.adapters.HTTPAdapter):
8+
@override
49
def close(self) -> None: ...
10+
@override
11+
def get_connection_with_tls_context(
12+
self,
13+
request: requests.PreparedRequest,
14+
verify: bool | str | None,
15+
proxies: Mapping[str, str] | None = None,
16+
cert: tuple[str, str] | str | None = None,
17+
) -> ConnectionPool: ...

0 commit comments

Comments
 (0)