Skip to content

Commit b8f900d

Browse files
Merge pull request #599 from dklimpel/fix_typing_containers_run
fix: typing in `podman.domain.containers_run`
2 parents c9ca28d + f5f9a41 commit b8f900d

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

podman/domain/containers_run.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def run(
2525
stderr=False,
2626
remove: bool = False,
2727
**kwargs,
28-
) -> Union[Container, Union[Generator[str, None, None], Iterator[str]]]:
28+
) -> Union[Container, Union[Generator[bytes, None, None], Iterator[bytes]]]:
2929
"""Run a container.
3030
3131
By default, run() will wait for the container to finish and return its logs.
@@ -66,20 +66,22 @@ def run(
6666
APIError: when Podman service reports an error
6767
"""
6868
if isinstance(image, Image):
69-
image = image.id
69+
image_id = image.id
70+
else:
71+
image_id = image
7072
if isinstance(command, str):
7173
command = [command]
7274

7375
try:
74-
container = self.create(image=image, command=command, **kwargs)
76+
container = self.create(image=image_id, command=command, **kwargs) # type: ignore[attr-defined]
7577
except ImageNotFound:
76-
self.podman_client.images.pull(
77-
image,
78+
self.podman_client.images.pull( # type: ignore[attr-defined]
79+
image_id,
7880
auth_config=kwargs.get("auth_config"),
7981
platform=kwargs.get("platform"),
8082
policy=kwargs.get("policy", "missing"),
8183
)
82-
container = self.create(image=image, command=command, **kwargs)
84+
container = self.create(image=image_id, command=command, **kwargs) # type: ignore[attr-defined]
8385

8486
container.start()
8587
container.reload()
@@ -116,6 +118,6 @@ def remove_container(container_object: Container) -> None:
116118
container.remove()
117119

118120
if exit_status != 0:
119-
raise ContainerError(container, exit_status, command, image, log_iter)
121+
raise ContainerError(container, exit_status, command, image_id, log_iter)
120122

121-
return log_iter if kwargs.get("stream", False) or log_iter is None else b"".join(log_iter)
123+
return log_iter if kwargs.get("stream", False) or log_iter is None else b"".join(log_iter) # type: ignore[return-value]

podman/errors/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def __init__(
115115
exit_status: int,
116116
command: Union[str, list[str]],
117117
image: str,
118-
stderr: Optional[Iterable[str]] = None,
118+
stderr: Optional[Iterable[bytes]] = None,
119119
): # pylint: disable=too-many-positional-arguments
120120
"""Initialize ContainerError.
121121

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ module = [
141141
"podman.domain.config",
142142
"podman.domain.containers",
143143
"podman.domain.containers_create",
144-
"podman.domain.containers_run",
145144
"podman.domain.events",
146145
"podman.domain.images_build",
147146
"podman.domain.images_manager",

0 commit comments

Comments
 (0)