Skip to content

Commit 888b9ff

Browse files
[docker] Add missing type annotations in docker.types (#15566)
1 parent 7500dfe commit 888b9ff

File tree

6 files changed

+113
-82
lines changed

6 files changed

+113
-82
lines changed

stubs/docker/docker/types/base.pyi

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
from _typeshed import Incomplete
21
from collections.abc import Mapping
2+
from typing import TypeVar
33

4-
class DictType(dict[str, Incomplete]):
5-
def __init__(self, init: Mapping[str, Incomplete]) -> None: ...
4+
_VT = TypeVar("_VT")
5+
6+
class DictType(dict[str, _VT]):
7+
def __init__(self, init: Mapping[str, _VT]) -> None: ...

stubs/docker/docker/types/containers.pyi

Lines changed: 53 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from _typeshed import Incomplete
21
from collections.abc import Iterable, Mapping
32
from typing import Any, Final, Literal
43

@@ -18,63 +17,80 @@ class LogConfigTypesEnum:
1817
FLUENTD: Final = "fluentd"
1918
NONE: Final = "none"
2019

21-
class LogConfig(DictType):
20+
class LogConfig(DictType[Any]):
2221
types: type[LogConfigTypesEnum]
23-
def __init__(self, **kwargs) -> None: ...
22+
def __init__(
23+
self, *, type: str = ..., Type: str = ..., config: dict[str, str] = ..., Config: dict[str, str] = ...
24+
) -> None: ...
2425
@property
25-
def type(self): ...
26+
def type(self) -> str: ...
2627
@type.setter
27-
def type(self, value) -> None: ...
28+
def type(self, value: str) -> None: ...
2829
@property
29-
def config(self): ...
30-
def set_config_value(self, key, value) -> None: ...
31-
def unset_config(self, key) -> None: ...
30+
def config(self) -> dict[str, str]: ...
31+
def set_config_value(self, key: str, value: str) -> None: ...
32+
def unset_config(self, key: str) -> None: ...
3233

33-
class Ulimit(DictType):
34-
def __init__(self, **kwargs) -> None: ...
34+
class Ulimit(DictType[Any]):
35+
def __init__(
36+
self, *, name: str = ..., Name: str = ..., soft: int = ..., Soft: int = ..., hard: int = ..., Hard: int = ...
37+
) -> None: ...
3538
@property
36-
def name(self): ...
39+
def name(self) -> str: ...
3740
@name.setter
38-
def name(self, value) -> None: ...
41+
def name(self, value: str) -> None: ...
3942
@property
40-
def soft(self): ...
43+
def soft(self) -> int | None: ...
4144
@soft.setter
42-
def soft(self, value) -> None: ...
45+
def soft(self, value: int | None) -> None: ...
4346
@property
44-
def hard(self): ...
47+
def hard(self) -> int | None: ...
4548
@hard.setter
46-
def hard(self, value) -> None: ...
49+
def hard(self, value: int | None) -> None: ...
4750

48-
class DeviceRequest(DictType):
49-
def __init__(self, **kwargs) -> None: ...
51+
class DeviceRequest(DictType[Any]):
52+
def __init__(
53+
self,
54+
*,
55+
driver: str = ...,
56+
Driver: str = ...,
57+
count: int = ...,
58+
Count: int = ...,
59+
device_ids: list[str] = ...,
60+
DeviceIDs: list[str] = ...,
61+
capabilities: list[list[str]] = ...,
62+
Capabilities: list[list[str]] = ...,
63+
options: dict[str, str] = ...,
64+
Options: dict[str, str] = ...,
65+
) -> None: ...
5066
@property
51-
def driver(self): ...
67+
def driver(self) -> str: ...
5268
@driver.setter
53-
def driver(self, value) -> None: ...
69+
def driver(self, value: str) -> None: ...
5470
@property
55-
def count(self): ...
71+
def count(self) -> int: ...
5672
@count.setter
57-
def count(self, value) -> None: ...
73+
def count(self, value: int) -> None: ...
5874
@property
59-
def device_ids(self): ...
75+
def device_ids(self) -> list[str]: ...
6076
@device_ids.setter
61-
def device_ids(self, value) -> None: ...
77+
def device_ids(self, value: list[str]) -> None: ...
6278
@property
63-
def capabilities(self): ...
79+
def capabilities(self) -> list[list[str]]: ...
6480
@capabilities.setter
65-
def capabilities(self, value) -> None: ...
81+
def capabilities(self, value: list[list[str]]) -> None: ...
6682
@property
67-
def options(self): ...
83+
def options(self) -> dict[str, str]: ...
6884
@options.setter
69-
def options(self, value) -> None: ...
85+
def options(self, value: dict[str, str]) -> None: ...
7086

71-
class HostConfig(dict[str, Incomplete]):
87+
class HostConfig(dict[str, Any]):
7288
def __init__(
7389
self,
7490
version: str,
7591
binds: dict[str, Mapping[str, str]] | list[str] | None = None,
76-
port_bindings: Mapping[int | str, Incomplete] | None = None,
77-
lxc_conf: dict[str, Incomplete] | list[dict[str, Incomplete]] | None = None,
92+
port_bindings: Mapping[int | str, Any] | None = None, # Any: int, str, tuple, dict, or list
93+
lxc_conf: dict[str, str] | list[dict[str, str]] | None = None,
7894
publish_all_ports: bool = False,
7995
links: dict[str, str] | dict[str, None] | dict[str, str | None] | Iterable[tuple[str, str | None]] | None = None,
8096
privileged: bool = False,
@@ -86,7 +102,7 @@ class HostConfig(dict[str, Incomplete]):
86102
cap_add: list[str] | None = None,
87103
cap_drop: list[str] | None = None,
88104
devices: list[str] | None = None,
89-
extra_hosts: dict[str, Incomplete] | list[Incomplete] | None = None,
105+
extra_hosts: dict[str, str] | list[str] | None = None,
90106
read_only: bool | None = None,
91107
pid_mode: str | None = None,
92108
ipc_mode: str | None = None,
@@ -113,15 +129,15 @@ class HostConfig(dict[str, Incomplete]):
113129
sysctls: dict[str, str] | None = None,
114130
tmpfs: dict[str, str] | None = None,
115131
oom_score_adj: int | None = None,
116-
dns_opt: list[Incomplete] | None = None,
132+
dns_opt: list[str] | None = None,
117133
cpu_shares: int | None = None,
118134
cpuset_cpus: str | None = None,
119135
userns_mode: str | None = None,
120136
uts_mode: str | None = None,
121137
pids_limit: int | None = None,
122138
isolation: str | None = None,
123139
auto_remove: bool = False,
124-
storage_opt: dict[Incomplete, Incomplete] | None = None,
140+
storage_opt: dict[str, str] | None = None,
125141
init: bool | None = None,
126142
init_path: str | None = None,
127143
volume_driver: str | None = None,
@@ -133,7 +149,7 @@ class HostConfig(dict[str, Incomplete]):
133149
mounts: list[Mount] | None = None,
134150
cpu_rt_period: int | None = None,
135151
cpu_rt_runtime: int | None = None,
136-
device_cgroup_rules: list[Incomplete] | None = None,
152+
device_cgroup_rules: list[str] | None = None,
137153
device_requests: list[DeviceRequest] | None = None,
138154
cgroupns: Literal["private", "host"] | None = None,
139155
) -> None: ...
@@ -143,7 +159,7 @@ def host_config_version_error(param: str, version: str, less_than: bool = True)
143159
def host_config_value_error(param: str, param_value: object) -> ValueError: ...
144160
def host_config_incompatible_error(param: str, param_value: str, incompatible_param: str) -> errors.InvalidArgument: ...
145161

146-
class ContainerConfig(dict[str, Incomplete]):
162+
class ContainerConfig(dict[str, Any]):
147163
def __init__(
148164
self,
149165
version: str,
@@ -156,7 +172,7 @@ class ContainerConfig(dict[str, Incomplete]):
156172
tty: bool = False,
157173
# list is invariant, enumerating all possible union combination would be too complex for:
158174
# list[str | int | tuple[int | str, str] | tuple[int | str, ...]]
159-
ports: dict[str, dict[Incomplete, Incomplete]] | list[Any] | None = None,
175+
ports: dict[str, dict[str, str]] | list[Any] | None = None,
160176
environment: dict[str, str] | list[str] | None = None,
161177
volumes: str | list[str] | None = None,
162178
network_disabled: bool = False,

stubs/docker/docker/types/daemon.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ from collections.abc import Iterator
22
from typing import Generic, TypeVar
33
from typing_extensions import Self
44

5+
from requests import Response
6+
57
_T_co = TypeVar("_T_co", covariant=True)
68

79
class CancellableStream(Generic[_T_co]):
8-
def __init__(self, stream: Iterator[_T_co], response) -> None: ...
10+
def __init__(self, stream: Iterator[_T_co], response: Response) -> None: ...
911
def __iter__(self) -> Self: ...
1012
def __next__(self) -> _T_co: ...
1113
next = __next__
Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,39 @@
1+
from typing import Any
2+
13
from .base import DictType
24

3-
class Healthcheck(DictType):
4-
def __init__(self, **kwargs) -> None: ...
5+
class Healthcheck(DictType[Any]):
6+
def __init__(
7+
self,
8+
*,
9+
test: str | list[str] | None = ...,
10+
Test: str | list[str] | None = ...,
11+
interval: int | None = ...,
12+
Interval: int | None = ...,
13+
timeout: int | None = ...,
14+
Timeout: int | None = ...,
15+
retries: int | None = ...,
16+
Retries: int | None = ...,
17+
start_period: int | None = ...,
18+
StartPeriod: int | None = ...,
19+
) -> None: ...
520
@property
6-
def test(self): ...
21+
def test(self) -> list[str] | None: ...
722
@test.setter
8-
def test(self, value) -> None: ...
23+
def test(self, value: str | list[str] | None) -> None: ...
924
@property
10-
def interval(self): ...
25+
def interval(self) -> int | None: ...
1126
@interval.setter
12-
def interval(self, value) -> None: ...
27+
def interval(self, value: int | None) -> None: ...
1328
@property
14-
def timeout(self): ...
29+
def timeout(self) -> int | None: ...
1530
@timeout.setter
16-
def timeout(self, value) -> None: ...
31+
def timeout(self, value: int | None) -> None: ...
1732
@property
18-
def retries(self): ...
33+
def retries(self) -> int | None: ...
1934
@retries.setter
20-
def retries(self, value) -> None: ...
35+
def retries(self, value: int | None) -> None: ...
2136
@property
22-
def start_period(self): ...
37+
def start_period(self) -> int | None: ...
2338
@start_period.setter
24-
def start_period(self, value) -> None: ...
39+
def start_period(self, value: int | None) -> None: ...

stubs/docker/docker/types/networks.pyi

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from _typeshed import Incomplete
21
from collections.abc import Iterable
2+
from typing import Any
33

4-
class EndpointConfig(dict[str, Incomplete]):
4+
class EndpointConfig(dict[str, Any]):
55
def __init__(
66
self,
77
version: str,
@@ -10,22 +10,19 @@ class EndpointConfig(dict[str, Incomplete]):
1010
ipv4_address: str | None = None,
1111
ipv6_address: str | None = None,
1212
link_local_ips: list[str] | None = None,
13-
driver_opt=None,
13+
driver_opt: dict[str, str] | None = None,
1414
mac_address: str | None = None,
1515
) -> None: ...
1616

17-
class NetworkingConfig(dict[str, Incomplete]):
17+
class NetworkingConfig(dict[str, Any]):
1818
def __init__(self, endpoints_config: EndpointConfig | None = None) -> None: ...
1919

20-
class IPAMConfig(dict[str, Incomplete]):
20+
class IPAMConfig(dict[str, Any]):
2121
def __init__(
22-
self,
23-
driver: str = "default",
24-
pool_configs: list[IPAMPool] | None = None,
25-
options: dict[Incomplete, Incomplete] | None = None,
22+
self, driver: str = "default", pool_configs: list[IPAMPool] | None = None, options: dict[str, str] | None = None
2623
) -> None: ...
2724

28-
class IPAMPool(dict[str, Incomplete]):
25+
class IPAMPool(dict[str, Any]):
2926
def __init__(
3027
self,
3128
subnet: str | None = None,

0 commit comments

Comments
 (0)