diff --git a/stubs/docker/docker/errors.pyi b/stubs/docker/docker/errors.pyi index fa443f0ff0e3..49e22900297a 100644 --- a/stubs/docker/docker/errors.pyi +++ b/stubs/docker/docker/errors.pyi @@ -1,5 +1,5 @@ from _typeshed import Incomplete -from collections.abc import Mapping +from collections.abc import Iterator, Mapping from typing import NoReturn from docker.models.containers import Container @@ -47,8 +47,8 @@ class StreamParseError(RuntimeError): class BuildError(DockerException): msg: str - build_log: str - def __init__(self, reason: str, build_log: str) -> None: ... + build_log: Iterator[dict[str, str]] + def __init__(self, reason: str, build_log: Iterator[dict[str, str]]) -> None: ... class ImageLoadError(DockerException): ... diff --git a/stubs/docker/docker/utils/json_stream.pyi b/stubs/docker/docker/utils/json_stream.pyi index a5c4ce4010a3..39ddd9d18cb9 100644 --- a/stubs/docker/docker/utils/json_stream.pyi +++ b/stubs/docker/docker/utils/json_stream.pyi @@ -1,10 +1,18 @@ -from _typeshed import Incomplete -from collections.abc import Generator +import json +from collections.abc import Callable, Generator, Iterator +from typing import Any +from typing_extensions import TypeAlias -json_decoder: Incomplete +json_decoder: json.JSONDecoder -def stream_as_text(stream) -> Generator[Incomplete, None, None]: ... -def json_splitter(buffer): ... -def json_stream(stream): ... -def line_splitter(buffer, separator: str = "\n"): ... -def split_buffer(stream, splitter: Incomplete | None = None, decoder=...) -> Generator[Incomplete, None, Incomplete]: ... +# Type alias for JSON, explained at: +# https://github.com/python/typing/issues/182#issuecomment-1320974824. +_JSON: TypeAlias = dict[str, _JSON] | list[_JSON] | str | int | float | bool | None + +def stream_as_text(stream: Iterator[str | bytes]) -> Generator[str, None, None]: ... +def json_splitter(buffer: str) -> tuple[_JSON, str] | None: ... +def json_stream(stream: Iterator[str]) -> Generator[_JSON, None, None]: ... +def line_splitter(buffer: str, separator: str = "\n") -> tuple[str, str] | None: ... +def split_buffer( + stream: Iterator[str | bytes], splitter: Callable[[str], tuple[str, str]] | None = None, decoder: Callable[[str], Any] = ... +) -> Generator[Any, None, None]: ...