Python code modernization, 1/n (#1141)

* Remove unicode text prefixes.

* Replace str.format() uses with f-strings.

* Replace % with f-strings, and do some cleanup.

* Fix wrong variable.

* Avoid unnecessary string conversion.
This commit is contained in:
Felix Fontein
2025-10-06 18:30:54 +02:00
committed by GitHub
parent 1f2817fa20
commit f45232635c
93 changed files with 930 additions and 1122 deletions
+5 -5
View File
@@ -121,7 +121,7 @@ stack_spec_diff:
definition.
sample: >
"stack_spec_diff":
{'test_stack_test_service': {u'TaskTemplate': {u'ContainerSpec': {delete: [u'Env']}}}}
{'test_stack_test_service': {'TaskTemplate': {'ContainerSpec': {delete: ['Env']}}}}
returned: on change
type: dict
"""
@@ -184,7 +184,7 @@ except ImportError:
def docker_stack_services(client, stack_name):
rc, out, err = client.call_cli("stack", "services", stack_name, "--format", "{{.Name}}")
if to_native(err) == "Nothing found in stack: %s\n" % stack_name:
if to_native(err) == f"Nothing found in stack: {stack_name}\n":
return []
return to_native(out).strip().split('\n')
@@ -230,7 +230,7 @@ def docker_stack_rm(client, stack_name, retries, interval):
command += ["--detach=false"]
rc, out, err = client.call_cli(*command)
while to_native(err) != "Nothing found in stack: %s\n" % stack_name and retries > 0:
while to_native(err) != f"Nothing found in stack: {stack_name}\n" and retries > 0:
sleep(interval)
retries = retries - 1
rc, out, err = client.call_cli(*command)
@@ -281,7 +281,7 @@ def main():
elif isinstance(compose_def, str):
compose_files.append(compose_def)
else:
client.fail("compose element '%s' must be a string or a dictionary" % compose_def)
client.fail(f"compose element '{compose_def}' must be a string or a dictionary")
before_stack_services = docker_stack_inspect(client, name)
@@ -340,7 +340,7 @@ def main():
)
client.module.exit_json(changed=False)
except DockerException as e:
client.fail('An unexpected Docker error occurred: {0}'.format(to_native(e)), exception=traceback.format_exc())
client.fail(f'An unexpected Docker error occurred: {e}', exception=traceback.format_exc())
if __name__ == "__main__":