Python code modernization, 5/n (#1165)

* Address raise-missing-from.

* Address simplifiable-if-expression.

* Address unnecessary-dunder-call.

* Address unnecessary-pass.

* Address use-list-literal.

* Address unused-variable.

* Address use-dict-literal.
This commit is contained in:
Felix Fontein
2025-10-12 16:02:27 +02:00
committed by GitHub
parent cad22de628
commit c75aa5dd64
66 changed files with 1549 additions and 1429 deletions
+8 -4
View File
@@ -178,7 +178,7 @@ class Connection(ConnectionBase):
)
chunks = b""
for key, event in events:
for key, dummy_event in events:
if key.fileobj == p.stdout:
chunk = p.stdout.read()
if chunk:
@@ -244,11 +244,13 @@ class Connection(ConnectionBase):
try:
with open(to_bytes(in_path, errors="surrogate_or_strict"), "rb") as in_file:
in_data = in_file.read()
rc, out, err = self.exec_command(cmd=["tee", out_path], in_data=in_data)
rc, dummy_out, err = self.exec_command(
cmd=["tee", out_path], in_data=in_data
)
if rc != 0:
raise AnsibleError(f"failed to transfer file to {out_path}: {err}")
except IOError as e:
raise AnsibleError(f"failed to transfer file to {out_path}: {e}")
raise AnsibleError(f"failed to transfer file to {out_path}: {e}") from e
def fetch_file(self, in_path, out_path):
super().fetch_file(in_path, out_path)
@@ -268,7 +270,9 @@ class Connection(ConnectionBase):
) as out_file:
out_file.write(out)
except IOError as e:
raise AnsibleError(f"failed to transfer file to {to_native(out_path)}: {e}")
raise AnsibleError(
f"failed to transfer file to {to_native(out_path)}: {e}"
) from e
def close(self):
"""terminate the connection; nothing to do here"""