Skip to content

Improve docker.types #13809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions stubs/docker/docker/api/container.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime
from _typeshed import Incomplete
from typing import Literal, TypedDict, overload, type_check_only
from typing import Any, Literal, TypedDict, overload, type_check_only
from typing_extensions import TypeAlias

from docker._types import WaitContainerResponse
Expand Down Expand Up @@ -61,7 +61,9 @@ class ContainerApiMixin:
detach: bool = False,
stdin_open: bool = False,
tty: bool = False,
ports: list[int] | None = None,
# list is invariant, enumerating all possible union combination would be too complex for:
# list[str | int | tuple[int | str, str] | tuple[int | str, ...]]
ports: dict[str, dict[Incomplete, Incomplete]] | list[Any] | None = None,
environment: dict[str, str] | list[str] | None = None,
volumes: str | list[str] | None = None,
network_disabled: bool = False,
Expand Down
3 changes: 2 additions & 1 deletion stubs/docker/docker/api/network.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from _typeshed import Incomplete
from collections.abc import Iterable
from typing import Any, Literal, TypedDict, type_check_only
from typing_extensions import TypeAlias

Expand Down Expand Up @@ -43,7 +44,7 @@ class NetworkApiMixin:
ipv4_address: Incomplete | None = None,
ipv6_address: Incomplete | None = None,
aliases: Incomplete | None = None,
links: Incomplete | None = None,
links: dict[str, str] | dict[str, None] | dict[str, str | None] | Iterable[tuple[str, str | None]] | None = None,
link_local_ips: Incomplete | None = None,
driver_opt: Incomplete | None = None,
mac_address: Incomplete | None = None,
Expand Down
19 changes: 10 additions & 9 deletions stubs/docker/docker/models/containers.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
from _typeshed import Incomplete
from collections.abc import Iterable, Mapping
from typing import Literal, NamedTuple, TypedDict, overload
from typing_extensions import NotRequired

Expand Down Expand Up @@ -152,7 +153,7 @@ class ContainerCollection(Collection[Container]):
entrypoint: str | list[str] | None = None,
environment: dict[str, str] | list[str] | None = None,
extra_hosts: dict[str, str] | None = None,
group_add: list[str | int] | None = None,
group_add: Iterable[str | int] | None = None,
healthcheck: dict[Incomplete, Incomplete] | None = None,
hostname: str | None = None,
init: bool | None = None,
Expand All @@ -161,7 +162,7 @@ class ContainerCollection(Collection[Container]):
isolation: str | None = None,
kernel_memory: str | int | None = None,
labels: dict[str, str] | list[str] | None = None,
links: dict[str, str | None] | None = None,
links: dict[str, str] | dict[str, None] | dict[str, str | None] | Iterable[tuple[str, str | None]] | None = None,
log_config: LogConfig | None = None,
lxc_conf: dict[Incomplete, Incomplete] | None = None,
mac_address: str | None = None,
Expand All @@ -181,7 +182,7 @@ class ContainerCollection(Collection[Container]):
pid_mode: str | None = None,
pids_limit: int | None = None,
platform: str | None = None,
ports: dict[str, int | list[int] | tuple[str, int] | None] | None = None,
ports: Mapping[str, int | list[int] | tuple[str, int] | None] | None = None,
privileged: bool = False,
publish_all_ports: bool = False,
read_only: bool | None = None,
Expand Down Expand Up @@ -247,7 +248,7 @@ class ContainerCollection(Collection[Container]):
entrypoint: str | list[str] | None = None,
environment: dict[str, str] | list[str] | None = None,
extra_hosts: dict[str, str] | None = None,
group_add: list[str | int] | None = None,
group_add: Iterable[str | int] | None = None,
healthcheck: dict[Incomplete, Incomplete] | None = None,
hostname: str | None = None,
init: bool | None = None,
Expand All @@ -256,7 +257,7 @@ class ContainerCollection(Collection[Container]):
isolation: str | None = None,
kernel_memory: str | int | None = None,
labels: dict[str, str] | list[str] | None = None,
links: dict[str, str | None] | None = None,
links: dict[str, str] | dict[str, None] | dict[str, str | None] | Iterable[tuple[str, str | None]] | None = None,
log_config: LogConfig | None = None,
lxc_conf: dict[Incomplete, Incomplete] | None = None,
mac_address: str | None = None,
Expand All @@ -276,7 +277,7 @@ class ContainerCollection(Collection[Container]):
pid_mode: str | None = None,
pids_limit: int | None = None,
platform: str | None = None,
ports: dict[str, int | list[int] | tuple[str, int] | None] | None = None,
ports: Mapping[str, int | list[int] | tuple[str, int] | None] | None = None,
privileged: bool = False,
publish_all_ports: bool = False,
read_only: bool | None = None,
Expand Down Expand Up @@ -338,7 +339,7 @@ class ContainerCollection(Collection[Container]):
entrypoint: str | list[str] | None = None,
environment: dict[str, str] | list[str] | None = None,
extra_hosts: dict[str, str] | None = None,
group_add: list[str | int] | None = None,
group_add: Iterable[str | int] | None = None,
healthcheck: dict[Incomplete, Incomplete] | None = None,
hostname: str | None = None,
init: bool | None = None,
Expand All @@ -347,7 +348,7 @@ class ContainerCollection(Collection[Container]):
isolation: str | None = None,
kernel_memory: str | int | None = None,
labels: dict[str, str] | list[str] | None = None,
links: dict[str, str | None] | None = None,
links: dict[str, str] | dict[str, None] | dict[str, str | None] | Iterable[tuple[str, str | None]] | None = None,
log_config: LogConfig | None = None,
lxc_conf: dict[Incomplete, Incomplete] | None = None,
mac_address: str | None = None,
Expand All @@ -367,7 +368,7 @@ class ContainerCollection(Collection[Container]):
pid_mode: str | None = None,
pids_limit: int | None = None,
platform: str | None = None,
ports: dict[str, int | list[int] | tuple[str, int] | None] | None = None,
ports: Mapping[str, int | list[int] | tuple[str, int] | None] | None = None,
privileged: bool = False,
publish_all_ports: bool = False,
read_only: bool | None = None,
Expand Down
66 changes: 36 additions & 30 deletions stubs/docker/docker/types/containers.pyi
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
from _typeshed import Incomplete
from typing import Literal
from collections.abc import Iterable, Mapping
from typing import Any, Final, Literal

from docker._types import ContainerWeightDevice

from .. import errors
from .base import DictType
from .healthcheck import Healthcheck
from .networks import NetworkingConfig
from .services import Mount

class LogConfigTypesEnum:
JSON: Incomplete
SYSLOG: Incomplete
JOURNALD: Incomplete
GELF: Incomplete
FLUENTD: Incomplete
NONE: Incomplete
JSON: Final = "json-file"
SYSLOG: Final = "syslog"
JOURNALD: Final = "journald"
GELF: Final = "gelf"
FLUENTD: Final = "fluentd"
NONE: Final = "none"

class LogConfig(DictType):
types: type[LogConfigTypesEnum]
Expand Down Expand Up @@ -68,21 +72,21 @@ class HostConfig(dict[str, Incomplete]):
def __init__(
self,
version: str,
binds: Incomplete | None = None,
port_bindings: Incomplete | None = None,
lxc_conf: dict[Incomplete, Incomplete] | None = None,
binds: dict[str, Mapping[str, str]] | list[str] | None = None,
port_bindings: Mapping[int | str, Incomplete] | None = None,
lxc_conf: dict[str, Incomplete] | list[dict[str, Incomplete]] | None = None,
publish_all_ports: bool = False,
links: dict[str, str | None] | None = None,
links: dict[str, str] | dict[str, None] | dict[str, str | None] | Iterable[tuple[str, str | None]] | None = None,
privileged: bool = False,
dns: list[Incomplete] | None = None,
dns_search: list[Incomplete] | None = None,
dns: list[str] | None = None,
dns_search: list[str] | None = None,
volumes_from: list[str] | None = None,
network_mode: str | None = None,
restart_policy: dict[Incomplete, Incomplete] | None = None,
restart_policy: Mapping[str, str | int] | None = None,
cap_add: list[str] | None = None,
cap_drop: list[str] | None = None,
devices: list[str] | None = None,
extra_hosts: dict[Incomplete, Incomplete] | None = None,
extra_hosts: dict[str, Incomplete] | list[Incomplete] | None = None,
read_only: bool | None = None,
pid_mode: str | None = None,
ipc_mode: str | None = None,
Expand All @@ -95,18 +99,18 @@ class HostConfig(dict[str, Incomplete]):
kernel_memory: str | int | None = None,
mem_swappiness: int | None = None,
cgroup_parent: str | None = None,
group_add: list[str | int] | None = None,
group_add: Iterable[str | int] | None = None,
cpu_quota: int | None = None,
cpu_period: int | None = None,
blkio_weight: int | None = None,
blkio_weight_device: list[ContainerWeightDevice] | None = None,
device_read_bps: Incomplete | None = None,
device_write_bps: Incomplete | None = None,
device_read_iops: Incomplete | None = None,
device_write_iops: Incomplete | None = None,
device_read_bps: list[Mapping[str, str | int]] | None = None,
device_write_bps: list[Mapping[str, str | int]] | None = None,
device_read_iops: list[Mapping[str, str | int]] | None = None,
device_write_iops: list[Mapping[str, str | int]] | None = None,
oom_kill_disable: bool = False,
shm_size: str | int | None = None,
sysctls: dict[Incomplete, Incomplete] | None = None,
sysctls: dict[str, str] | None = None,
tmpfs: dict[str, str] | None = None,
oom_score_adj: int | None = None,
dns_opt: list[Incomplete] | None = None,
Expand Down Expand Up @@ -134,35 +138,37 @@ class HostConfig(dict[str, Incomplete]):
cgroupns: Literal["private", "host"] | None = None,
) -> None: ...

def host_config_type_error(param, param_value, expected): ...
def host_config_version_error(param, version, less_than: bool = True): ...
def host_config_value_error(param, param_value): ...
def host_config_incompatible_error(param, param_value, incompatible_param): ...
def host_config_type_error(param: str, param_value: object, expected: str) -> TypeError: ...
def host_config_version_error(param: str, version: str, less_than: bool = True) -> errors.InvalidVersion: ...
def host_config_value_error(param: str, param_value: object) -> ValueError: ...
def host_config_incompatible_error(param: str, param_value: str, incompatible_param: str) -> errors.InvalidArgument: ...

class ContainerConfig(dict[str, Incomplete]):
def __init__(
self,
version: str,
image,
image: str,
command: str | list[str],
hostname: str | None = None,
user: str | int | None = None,
detach: bool = False,
stdin_open: bool = False,
tty: bool = False,
ports: dict[str, int | list[int] | tuple[str, int] | None] | None = None,
# list is invariant, enumerating all possible union combination would be too complex for:
# list[str | int | tuple[int | str, str] | tuple[int | str, ...]]
ports: dict[str, dict[Incomplete, Incomplete]] | list[Any] | None = None,
environment: dict[str, str] | list[str] | None = None,
volumes: str | list[str] | None = None,
network_disabled: bool = False,
entrypoint: str | list[str] | None = None,
working_dir: str | None = None,
domainname: str | None = None,
host_config: Incomplete | None = None,
host_config: HostConfig | None = None,
mac_address: str | None = None,
labels: dict[str, str] | list[str] | None = None,
stop_signal: str | None = None,
networking_config: Incomplete | None = None,
healthcheck: Incomplete | None = None,
networking_config: NetworkingConfig | None = None,
healthcheck: Healthcheck | None = None,
stop_timeout: int | None = None,
runtime: str | None = None,
) -> None: ...
30 changes: 17 additions & 13 deletions stubs/docker/docker/types/networks.pyi
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
from _typeshed import Incomplete
from collections.abc import Iterable

class EndpointConfig(dict[str, Incomplete]):
def __init__(
self,
version,
aliases: Incomplete | None = None,
links: Incomplete | None = None,
ipv4_address: Incomplete | None = None,
ipv6_address: Incomplete | None = None,
link_local_ips: Incomplete | None = None,
version: str,
aliases: list[Incomplete] | None = None,
links: dict[str, str] | dict[str, None] | dict[str, str | None] | Iterable[tuple[str, str | None]] | None = None,
ipv4_address: str | None = None,
ipv6_address: str | None = None,
link_local_ips: list[str] | None = None,
driver_opt: Incomplete | None = None,
mac_address: Incomplete | None = None,
mac_address: str | None = None,
) -> None: ...

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

class IPAMConfig(dict[str, Incomplete]):
def __init__(
self, driver: str = "default", pool_configs: Incomplete | None = None, options: Incomplete | None = None
self,
driver: str = "default",
pool_configs: list[IPAMPool] | None = None,
options: dict[Incomplete, Incomplete] | None = None,
) -> None: ...

class IPAMPool(dict[str, Incomplete]):
def __init__(
self,
subnet: Incomplete | None = None,
iprange: Incomplete | None = None,
gateway: Incomplete | None = None,
aux_addresses: Incomplete | None = None,
subnet: str | None = None,
iprange: str | None = None,
gateway: str | None = None,
aux_addresses: dict[str, str] | None = None,
) -> None: ...
Loading