use f-strings in module utils (#10901)

* use f-strings in module utils

* Apply suggestions from code review

Co-authored-by: Felix Fontein <felix@fontein.de>

* remove unused imports

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Alexei Znamensky
2025-10-11 22:43:43 +13:00
committed by GitHub
parent 74b6a0294a
commit b85e263466
51 changed files with 270 additions and 382 deletions

View File

@@ -38,7 +38,7 @@ def module_fails_on_exception(func):
@wraps(func)
def wrapper(self, *args, **kwargs):
def fix_key(k):
return k if k not in conflict_list else "_" + k
return k if k not in conflict_list else f"_{k}"
def fix_var_conflicts(output):
result = {fix_key(k): v for k, v in output.items()}
@@ -56,7 +56,7 @@ def module_fails_on_exception(func):
except Exception as e:
# patchy solution to resolve conflict with output variables
output = fix_var_conflicts(self.output)
msg = "Module failed with exception: {0}".format(str(e).strip())
msg = f"Module failed with exception: {str(e).strip()}"
self.module.fail_json(msg=msg, exception=traceback.format_exc(),
output=self.output, vars=self.vars.output(), **output)
return wrapper