From 25f89d3663fab95a01b32c4c2d60056358ed9112 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Tue, 7 Oct 2025 22:06:24 +0200 Subject: [PATCH] Address possibly-used-before-assignment. --- .pylintrc | 1 - plugins/connection/docker.py | 2 ++ plugins/connection/nsenter.py | 2 ++ plugins/module_utils/_module_container/base.py | 2 +- plugins/modules/docker_compose_v2.py | 2 ++ 5 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.pylintrc b/.pylintrc index c75bf862..d0f45ad0 100644 --- a/.pylintrc +++ b/.pylintrc @@ -402,7 +402,6 @@ disable=raw-checker-failed, no-member, no-name-in-module, not-an-iterable, - possibly-used-before-assignment, protected-access, raise-missing-from, redefined-outer-name, # needed for test fixtures diff --git a/plugins/connection/docker.py b/plugins/connection/docker.py index fb36118d..f8122ff6 100644 --- a/plugins/connection/docker.py +++ b/plugins/connection/docker.py @@ -425,11 +425,13 @@ class Connection(ConnectionBase): + to_native(become_output) ) + chunk = None for key, event in events: if key.fileobj == p.stdout: chunk = p.stdout.read() elif key.fileobj == p.stderr: chunk = p.stderr.read() + # TODO: avoid chunk being set multiple times! if not chunk: stdout, stderr = p.communicate() diff --git a/plugins/connection/nsenter.py b/plugins/connection/nsenter.py index a3e86022..d029091f 100644 --- a/plugins/connection/nsenter.py +++ b/plugins/connection/nsenter.py @@ -177,11 +177,13 @@ class Connection(ConnectionBase): + to_native(become_output) ) + chunk = None for key, event in events: if key.fileobj == p.stdout: chunk = p.stdout.read() elif key.fileobj == p.stderr: chunk = p.stderr.read() + # TODO: avoid chunk being set multiple times! if not chunk: stdout, stderr = p.communicate() diff --git a/plugins/module_utils/_module_container/base.py b/plugins/module_utils/_module_container/base.py index 17a46fa2..b9af2291 100644 --- a/plugins/module_utils/_module_container/base.py +++ b/plugins/module_utils/_module_container/base.py @@ -859,7 +859,7 @@ def _preprocess_ports(module, values): else: port_binds = len(container_ports) * [(ipaddr,)] else: - module.fail_json( + return module.fail_json( msg=f'Invalid port description "{port}" - expected 1 to 3 colon-separated parts, but got {p_len}. ' "Maybe you forgot to use square brackets ([...]) around an IPv6 address?" ) diff --git a/plugins/modules/docker_compose_v2.py b/plugins/modules/docker_compose_v2.py index e1cd7973..6bde840a 100644 --- a/plugins/modules/docker_compose_v2.py +++ b/plugins/modules/docker_compose_v2.py @@ -499,6 +499,8 @@ class ServicesManager(BaseComposeManager): result = self.cmd_restart() elif self.state == "absent": result = self.cmd_down() + else: + raise AssertionError("Unexpected state") result["containers"] = self.list_containers() result["images"] = self.list_images()