diff --git a/stubs/docker/@tests/test_cases/check_attach.py b/stubs/docker/@tests/test_cases/check_attach.py new file mode 100644 index 000000000000..802099b9e2c2 --- /dev/null +++ b/stubs/docker/@tests/test_cases/check_attach.py @@ -0,0 +1,12 @@ +from __future__ import annotations + +from typing_extensions import assert_type + +from docker.models.containers import Container + + +def check_attach(c: Container) -> None: + assert_type(c.attach(), bytes) + assert_type(c.attach(stream=False), bytes) + for line in c.attach(stream=True): + assert_type(line, bytes) diff --git a/stubs/docker/docker/api/container.pyi b/stubs/docker/docker/api/container.pyi index f8e225493ee6..fb676cbb3e0c 100644 --- a/stubs/docker/docker/api/container.pyi +++ b/stubs/docker/docker/api/container.pyi @@ -24,15 +24,49 @@ class _TopResult(TypedDict): _Container: TypeAlias = _HasId | _HasID | str class ContainerApiMixin: + @overload def attach( self, container: _Container, stdout: bool = True, stderr: bool = True, - stream: bool = False, + stream: Literal[False] = False, logs: bool = False, - demux: bool = False, - ): ... + demux: Literal[False] = False, + ) -> bytes: ... + @overload + def attach( + self, + container: _Container, + stdout: bool = True, + stderr: bool = True, + stream: Literal[False] = False, + logs: bool = False, + *, + demux: Literal[True], + ) -> tuple[bytes | None, bytes | None]: ... + @overload + def attach( + self, + container: _Container, + stdout: bool = True, + stderr: bool = True, + *, + stream: Literal[True], + logs: bool = False, + demux: Literal[False] = False, + ) -> CancellableStream[bytes]: ... + @overload + def attach( + self, + container: _Container, + stdout: bool = True, + stderr: bool = True, + *, + stream: Literal[True], + logs: bool = False, + demux: Literal[True], + ) -> CancellableStream[tuple[bytes | None, bytes | None]]: ... def attach_socket(self, container: _Container, params=None, ws: bool = False): ... def commit( self, diff --git a/stubs/docker/docker/models/containers.pyi b/stubs/docker/docker/models/containers.pyi index 67097d2cc6bd..4bb709249df7 100644 --- a/stubs/docker/docker/models/containers.pyi +++ b/stubs/docker/docker/models/containers.pyi @@ -39,9 +39,40 @@ class Container(Model): def health(self) -> str: ... @property def ports(self) -> dict[Incomplete, Incomplete]: ... + @overload + def attach( + self, + *, + stdout: bool = True, + stderr: bool = True, + stream: Literal[False] = False, + logs: bool = False, + demux: Literal[False] = False, + ) -> bytes: ... + @overload + def attach( + self, + *, + stdout: bool = True, + stderr: bool = True, + stream: Literal[False] = False, + logs: bool = False, + demux: Literal[True], + ) -> tuple[bytes | None, bytes | None]: ... + @overload + def attach( + self, + *, + stdout: bool = True, + stderr: bool = True, + stream: Literal[True], + logs: bool = False, + demux: Literal[False] = False, + ) -> CancellableStream[bytes]: ... + @overload def attach( - self, **kwargs - ) -> str | tuple[str | None, str | None] | CancellableStream[str] | CancellableStream[tuple[str | None, str | None]]: ... + self, *, stdout: bool = True, stderr: bool = True, stream: Literal[True], logs: bool = False, demux: Literal[True] + ) -> CancellableStream[tuple[bytes | None, bytes | None]]: ... def attach_socket(self, **kwargs) -> SocketIO | _BufferedReaderStream | SSHSocket: ... def commit(self, repository: str | None = None, tag: str | None = None, **kwargs) -> Image: ... def diff(self) -> list[dict[str, Incomplete]]: ...