From 7cb2bacf056a9c7282884296c42fef0439985969 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sun, 16 Nov 2025 12:02:47 +0100 Subject: [PATCH] Remove superfluous conversions/assignments. --- plugins/connection/docker_api.py | 4 +--- plugins/modules/docker_compose_v2_exec.py | 3 +-- plugins/modules/docker_compose_v2_run.py | 3 +-- plugins/modules/docker_container_exec.py | 5 ++--- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/plugins/connection/docker_api.py b/plugins/connection/docker_api.py index 3fd1f3e4..afd6f9ec 100644 --- a/plugins/connection/docker_api.py +++ b/plugins/connection/docker_api.py @@ -284,9 +284,7 @@ class Connection(ConnectionBase): f"Non-string {what.lower()} found for extra_env option. Ambiguous env options must be " f"wrapped in quotes to avoid them being interpreted. {what}: {val!r}" ) - kk = to_text(k, errors="surrogate_or_strict") - vv = to_text(v, errors="surrogate_or_strict") - data["Env"].append(f"{kk}={vv}") + data["Env"].append(f"{k}={v}") if self.get_option("working_dir") is not None: data["WorkingDir"] = self.get_option("working_dir") diff --git a/plugins/modules/docker_compose_v2_exec.py b/plugins/modules/docker_compose_v2_exec.py index 1ab738a1..45682f88 100644 --- a/plugins/modules/docker_compose_v2_exec.py +++ b/plugins/modules/docker_compose_v2_exec.py @@ -210,13 +210,12 @@ class ExecManager(BaseComposeManager): self.stdin += "\n" if self.env is not None: - for name, value in list(self.env.items()): + for name, value in self.env.items(): if not isinstance(value, str): self.fail( "Non-string value found for env option. Ambiguous env options must be " f"wrapped in quotes to avoid them being interpreted. Key: {name}" ) - self.env[name] = to_text(value, errors="surrogate_or_strict") def get_exec_cmd(self, dry_run: bool) -> list[str]: args = self.get_base_args(plain_progress=True) + ["exec"] diff --git a/plugins/modules/docker_compose_v2_run.py b/plugins/modules/docker_compose_v2_run.py index 51da9f55..eaf037d6 100644 --- a/plugins/modules/docker_compose_v2_run.py +++ b/plugins/modules/docker_compose_v2_run.py @@ -296,13 +296,12 @@ class ExecManager(BaseComposeManager): self.stdin += "\n" if self.env is not None: - for name, value in list(self.env.items()): + for name, value in self.env.items(): if not isinstance(value, str): self.fail( "Non-string value found for env option. Ambiguous env options must be " f"wrapped in quotes to avoid them being interpreted. Key: {name}" ) - self.env[name] = to_text(value, errors="surrogate_or_strict") def get_run_cmd(self, dry_run: bool) -> list[str]: args = self.get_base_args(plain_progress=True) + ["run"] diff --git a/plugins/modules/docker_container_exec.py b/plugins/modules/docker_container_exec.py index 99651f4e..2086100a 100644 --- a/plugins/modules/docker_container_exec.py +++ b/plugins/modules/docker_container_exec.py @@ -221,16 +221,15 @@ def main() -> None: stdin: str | None = client.module.params["stdin"] strip_empty_ends: bool = client.module.params["strip_empty_ends"] tty: bool = client.module.params["tty"] - env: dict[str, t.Any] = client.module.params["env"] + env: dict[str, t.Any] | None = client.module.params["env"] if env is not None: - for name, value in list(env.items()): + for name, value in env.items(): if not isinstance(value, str): client.module.fail_json( msg="Non-string value found for env option. Ambiguous env options must be " f"wrapped in quotes to avoid them being interpreted. Key: {name}" ) - env[name] = to_text(value, errors="surrogate_or_strict") if command is not None: argv = shlex.split(command)