Skip to content

Commit 40f0894

Browse files
authored
[docker-py] Add some return types to DockerClient method (#15069)
1 parent bc805f6 commit 40f0894

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

stubs/docker/docker/api/daemon.pyi

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
from _typeshed import Incomplete
21
from datetime import datetime
3-
from typing import Any
2+
from typing import Any, Literal, overload
43

54
from docker.types.daemon import CancellableStream
65

76
class DaemonApiMixin:
87
def df(self) -> dict[str, Any]: ...
8+
@overload
99
def events(
1010
self,
1111
since: datetime | int | None = None,
1212
until: datetime | int | None = None,
1313
filters: dict[str, Any] | None = None,
14-
decode: bool | None = None,
15-
) -> CancellableStream[Incomplete]: ...
14+
decode: Literal[False] | None = None,
15+
) -> CancellableStream[str]: ...
16+
@overload
17+
def events(
18+
self,
19+
since: datetime | int | None = None,
20+
until: datetime | int | None = None,
21+
filters: dict[str, Any] | None = None,
22+
decode: Literal[True] = ...,
23+
) -> CancellableStream[dict[str, Any]]: ...
1624
def info(self) -> dict[str, Any]: ...
1725
def login(
1826
self,

stubs/docker/docker/client.pyi

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections.abc import Iterable
2-
from typing import NoReturn, Protocol, type_check_only
2+
from typing import Any, Literal, NoReturn, Protocol, overload, type_check_only
33

44
from docker import APIClient
55
from docker.models.configs import ConfigCollection
@@ -12,6 +12,7 @@ from docker.models.secrets import SecretCollection
1212
from docker.models.services import ServiceCollection
1313
from docker.models.swarm import Swarm
1414
from docker.models.volumes import VolumeCollection
15+
from docker.types import CancellableStream
1516

1617
@type_check_only
1718
class _Environ(Protocol):
@@ -51,13 +52,16 @@ class DockerClient:
5152
def swarm(self) -> Swarm: ...
5253
@property
5354
def volumes(self) -> VolumeCollection: ...
54-
def events(self, *args, **kwargs): ...
55-
def df(self): ...
56-
def info(self, *args, **kwargs): ...
57-
def login(self, *args, **kwargs): ...
58-
def ping(self, *args, **kwargs): ...
59-
def version(self, *args, **kwargs): ...
60-
def close(self): ...
55+
@overload
56+
def events(self, *args, decode: Literal[False] | None = None, **kwargs) -> CancellableStream[str]: ...
57+
@overload
58+
def events(self, *args, decode: Literal[True] = ..., **kwargs) -> CancellableStream[dict[str, Any]]: ...
59+
def df(self) -> dict[str, Any]: ...
60+
def info(self, *args, **kwargs) -> dict[str, Any]: ...
61+
def login(self, *args, **kwargs) -> dict[str, Any]: ...
62+
def ping(self, *args, **kwargs) -> bool: ...
63+
def version(self, *args, **kwargs) -> dict[str, Any]: ...
64+
def close(self) -> None: ...
6165
def __getattr__(self, name: str) -> NoReturn: ...
6266

6367
from_env = DockerClient.from_env

0 commit comments

Comments
 (0)