Skip to content

Commit f064c2b

Browse files
authored
[docker] Replace *args and **kwargs with explicit parameters (#16045)
1 parent 5e8f83e commit f064c2b

21 files changed

Lines changed: 444 additions & 168 deletions

stubs/docker/@tests/stubtest_allowlist.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ docker.transport.sshconn
66
# model is always set by child classes
77
docker.models.resource.Collection.model
88

9-
# keyword arguments are now unsupported
10-
docker.api.container.ContainerApiMixin.start
11-
129
# implementation has *args and **kwargs params that can't be used
10+
docker.api.container.ContainerApiMixin.start
1311
docker.client.DockerClient.info
1412
docker.client.DockerClient.ping
1513

stubs/docker/docker/api/config.pyi

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
from _typeshed import Incomplete
2+
13
class ConfigApiMixin:
2-
def create_config(self, name, data, labels=None, templating=None): ...
4+
def create_config(
5+
self,
6+
name: str,
7+
data: bytes,
8+
labels: dict[Incomplete, Incomplete] | None = None,
9+
templating: dict[Incomplete, Incomplete] | None = None,
10+
): ...
311
def inspect_config(self, id): ...
412
def remove_config(self, id): ...
513
def configs(self, filters=None): ...

stubs/docker/docker/api/container.pyi

Lines changed: 121 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
import datetime
22
from _typeshed import Incomplete
3+
from collections.abc import Iterable, Mapping
34
from typing import Any, Literal, TypeAlias, TypedDict, overload, type_check_only
5+
from typing_extensions import NotRequired
46

5-
from docker._types import WaitContainerResponse
7+
from docker._types import ContainerWeightDevice, WaitContainerResponse
8+
from docker.types.containers import DeviceRequest, LogConfig, Ulimit
69
from docker.types.daemon import CancellableStream
10+
from docker.types.healthcheck import Healthcheck
11+
from docker.types.services import Mount
712

813
from ..types import ContainerConfig, EndpointConfig, HostConfig, NetworkingConfig
914

15+
@type_check_only
16+
class _RestartPolicy(TypedDict):
17+
MaximumRetryCount: NotRequired[int]
18+
Name: NotRequired[Literal["always", "on-failure"]]
19+
1020
@type_check_only
1121
class _HasId(TypedDict):
1222
Id: str
@@ -121,11 +131,116 @@ class ContainerApiMixin:
121131
use_config_proxy: bool = True,
122132
platform: str | None = None,
123133
): ...
124-
def create_container_config(self, *args, **kwargs) -> ContainerConfig: ...
134+
# Please keep in sync with docker.types.ContainerConfig
135+
def create_container_config(
136+
self,
137+
image: str,
138+
command: str | list[str],
139+
hostname: str | None = None,
140+
user: str | int | None = None,
141+
detach: bool = False,
142+
stdin_open: bool = False,
143+
tty: bool = False,
144+
# list is invariant, enumerating all possible union combination would be too complex for:
145+
# list[str | int | tuple[int | str, str] | tuple[int | str, ...]]
146+
ports: dict[str, dict[str, str]] | list[Any] | None = None,
147+
environment: dict[str, str] | list[str] | None = None,
148+
volumes: str | list[str] | None = None,
149+
network_disabled: bool = False,
150+
entrypoint: str | list[str] | None = None,
151+
working_dir: str | None = None,
152+
domainname: str | None = None,
153+
host_config: HostConfig | None = None,
154+
mac_address: str | None = None,
155+
labels: dict[str, str] | list[str] | None = None,
156+
stop_signal: str | None = None,
157+
networking_config: NetworkingConfig | None = None,
158+
healthcheck: Healthcheck | None = None,
159+
stop_timeout: int | None = None,
160+
runtime: str | None = None,
161+
) -> ContainerConfig: ...
125162
def create_container_from_config(self, config, name=None, platform=None): ...
126-
def create_host_config(self, *args, **kwargs) -> HostConfig: ...
127-
def create_networking_config(self, *args, **kwargs) -> NetworkingConfig: ...
128-
def create_endpoint_config(self, *args, **kwargs) -> EndpointConfig: ...
163+
# Please keep in sync with docker.types.HostConfig
164+
def create_host_config(
165+
self,
166+
binds: dict[str, Mapping[str, str]] | list[str] | None = None,
167+
port_bindings: Mapping[int | str, Any] | None = None, # Any: int, str, tuple, dict, or list
168+
lxc_conf: dict[str, str] | list[dict[str, str]] | None = None,
169+
publish_all_ports: bool = False,
170+
links: dict[str, str] | dict[str, None] | dict[str, str | None] | Iterable[tuple[str, str | None]] | None = None,
171+
privileged: bool = False,
172+
dns: list[str] | None = None,
173+
dns_search: list[str] | None = None,
174+
volumes_from: list[str] | None = None,
175+
network_mode: str | None = None,
176+
restart_policy: Mapping[str, str | int] | None = None,
177+
cap_add: list[str] | None = None,
178+
cap_drop: list[str] | None = None,
179+
devices: list[str] | None = None,
180+
extra_hosts: dict[str, str] | list[str] | None = None,
181+
read_only: bool | None = None,
182+
pid_mode: str | None = None,
183+
ipc_mode: str | None = None,
184+
security_opt: list[str] | None = None,
185+
ulimits: list[Ulimit] | None = None,
186+
log_config: LogConfig | None = None,
187+
mem_limit: str | int | None = None,
188+
memswap_limit: str | int | None = None,
189+
mem_reservation: str | int | None = None,
190+
kernel_memory: str | int | None = None,
191+
mem_swappiness: int | None = None,
192+
cgroup_parent: str | None = None,
193+
group_add: Iterable[str | int] | None = None,
194+
cpu_quota: int | None = None,
195+
cpu_period: int | None = None,
196+
blkio_weight: int | None = None,
197+
blkio_weight_device: list[ContainerWeightDevice] | None = None,
198+
device_read_bps: list[Mapping[str, str | int]] | None = None,
199+
device_write_bps: list[Mapping[str, str | int]] | None = None,
200+
device_read_iops: list[Mapping[str, str | int]] | None = None,
201+
device_write_iops: list[Mapping[str, str | int]] | None = None,
202+
oom_kill_disable: bool = False,
203+
shm_size: str | int | None = None,
204+
sysctls: dict[str, str] | None = None,
205+
tmpfs: dict[str, str] | None = None,
206+
oom_score_adj: int | None = None,
207+
dns_opt: list[str] | None = None,
208+
cpu_shares: int | None = None,
209+
cpuset_cpus: str | None = None,
210+
userns_mode: str | None = None,
211+
uts_mode: str | None = None,
212+
pids_limit: int | None = None,
213+
isolation: str | None = None,
214+
auto_remove: bool = False,
215+
storage_opt: dict[str, str] | None = None,
216+
init: bool | None = None,
217+
init_path: str | None = None,
218+
volume_driver: str | None = None,
219+
cpu_count: int | None = None,
220+
cpu_percent: int | None = None,
221+
nano_cpus: int | None = None,
222+
cpuset_mems: str | None = None,
223+
runtime: str | None = None,
224+
mounts: list[Mount] | None = None,
225+
cpu_rt_period: int | None = None,
226+
cpu_rt_runtime: int | None = None,
227+
device_cgroup_rules: list[str] | None = None,
228+
device_requests: list[DeviceRequest] | None = None,
229+
cgroupns: Literal["private", "host"] | None = None,
230+
) -> HostConfig: ...
231+
# Please keep in sync with docker.types.NetworkingConfig
232+
def create_networking_config(self, endpoints_config: EndpointConfig | None = None) -> NetworkingConfig: ...
233+
# Please keep in sync with docker.types.EndpointConfig
234+
def create_endpoint_config(
235+
self,
236+
aliases: list[str] | None = None,
237+
links: dict[str, str] | dict[str, None] | dict[str, str | None] | Iterable[tuple[str, str | None]] | None = None,
238+
ipv4_address: str | None = None,
239+
ipv6_address: str | None = None,
240+
link_local_ips: list[str] | None = None,
241+
driver_opt: dict[str, str] | None = None,
242+
mac_address: str | None = None,
243+
) -> EndpointConfig: ...
129244
def diff(self, container: _Container) -> list[dict[Incomplete, Incomplete]]: ...
130245
def export(self, container: _Container, chunk_size: int | None = 2097152): ...
131246
def get_archive(
@@ -201,7 +316,7 @@ class ContainerApiMixin:
201316
mem_reservation: float | str | None = None,
202317
memswap_limit: int | str | None = None,
203318
kernel_memory: int | str | None = None,
204-
restart_policy=None,
319+
restart_policy: _RestartPolicy | None = None,
205320
): ...
206321
def wait(
207322
self,

stubs/docker/docker/api/image.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ class ImageApiMixin:
3838
def push(self, repository: str, tag: str | None = None, stream: bool = False, auth_config=None, decode: bool = False): ...
3939
def remove_image(self, image: str, force: bool = False, noprune: bool = False): ...
4040
def search(self, term: str, limit: int | None = None): ...
41-
def tag(self, image, repository, tag: str | None = None, force: bool = False): ...
41+
def tag(self, image, repository, tag: str | None = None, force: bool = False) -> bool: ...
4242

4343
def is_file(src: str) -> bool: ...

stubs/docker/docker/api/network.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from _typeshed import Incomplete
12
from collections.abc import Iterable
23
from typing import Any, Literal, TypeAlias, TypedDict, type_check_only
34

@@ -15,7 +16,7 @@ _Network: TypeAlias = _HasId | _HasID | str
1516
_Container: TypeAlias = _HasId | _HasID | str
1617

1718
class NetworkApiMixin:
18-
def networks(self, names=None, ids=None, filters=None): ...
19+
def networks(self, names: list[Incomplete] | None = None, ids: list[Incomplete] | None = None, filters=None): ...
1920
def create_network(
2021
self,
2122
name: str,

stubs/docker/docker/client.pyi

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from _typeshed import Incomplete
22
from collections.abc import Iterable, Mapping
3+
from datetime import datetime
34
from typing import Any, Literal, NoReturn, Protocol, overload, type_check_only
45

56
from docker import APIClient
@@ -83,13 +84,28 @@ class DockerClient:
8384
@property
8485
def volumes(self) -> VolumeCollection: ...
8586

87+
# Please keep in sync with docker.api.daemon.DaemonApiMixin.events
8688
@overload
87-
def events(self, *args, decode: Literal[False] | None = None, **kwargs) -> CancellableStream[str]: ...
89+
def events(
90+
self,
91+
since: datetime | int | None = None,
92+
until: datetime | int | None = None,
93+
filters: dict[str, Any] | None = None,
94+
decode: Literal[False] | None = None,
95+
) -> CancellableStream[str]: ...
8896
@overload
89-
def events(self, *args, decode: Literal[True] = ..., **kwargs) -> CancellableStream[dict[str, Any]]: ...
97+
def events(
98+
self,
99+
since: datetime | int | None = None,
100+
until: datetime | int | None = None,
101+
filters: dict[str, Any] | None = None,
102+
decode: Literal[True] = ...,
103+
) -> CancellableStream[dict[str, Any]]: ...
90104

91105
def df(self) -> dict[str, Any]: ...
106+
# Please keep in sync with docker.api.daemon.DaemonApiMixin.info
92107
def info(self) -> dict[str, Any]: ...
108+
# Please keep in sync with docker.api.daemon.DaemonApiMixin.login
93109
def login(
94110
self,
95111
username: str,
@@ -99,7 +115,9 @@ class DockerClient:
99115
reauth: bool = False,
100116
dockercfg_path: str | None = None,
101117
) -> dict[str, Any]: ...
118+
# Please keep in sync with docker.api.daemon.DaemonApiMixin.ping
102119
def ping(self) -> bool: ...
120+
# Please keep in sync with docker.api.daemon.DaemonApiMixin.version
103121
def version(self, api_version: bool = True) -> dict[str, Any]: ...
104122
def close(self) -> None: ...
105123
def __getattr__(self, name: str) -> NoReturn: ...

stubs/docker/docker/models/configs.pyi

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import builtins
1+
from _typeshed import Incomplete
2+
from builtins import list as _list
23

34
from .resource import Collection, Model
45

@@ -10,6 +11,15 @@ class Config(Model):
1011

1112
class ConfigCollection(Collection[Config]):
1213
model: type[Config]
13-
def create(self, **kwargs) -> Config: ... # type: ignore[override]
14+
# Please keep in sync with docker.api.config.ConfigApiMixin.create_config
15+
def create( # type: ignore[override]
16+
self,
17+
*,
18+
name: str,
19+
data: bytes,
20+
labels: dict[Incomplete, Incomplete] | None = None,
21+
templating: dict[Incomplete, Incomplete] | None = None,
22+
) -> Config: ...
1423
def get(self, config_id: str) -> Config: ...
15-
def list(self, **kwargs) -> builtins.list[Config]: ...
24+
# Please keep in sync with docker.api.config.ConfigApiMixin.configs
25+
def list(self, *, filters=None) -> _list[Config]: ...

0 commit comments

Comments
 (0)