mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-07-29 11:55:04 +00:00
Python code modernization, 4/n (#1162)
* Address attribute-defined-outside-init. * Address broad-exception-raised. * Address broad-exception-caught. * Address consider-iterating-dictionary. * Address consider-using-dict-comprehension. * Address consider-using-f-string. * Address consider-using-in. * Address consider-using-max-builtin. * Address some consider-using-with. * Address invalid-name. * Address keyword-arg-before-vararg. * Address line-too-long. * Address no-else-continue. * Address no-else-raise. * Address no-else-return. * Remove broken dead code. * Make consider-using-f-string changes compatible with older Python versions. * Python 3.11 and earlier apparently do not like multi-line f-strings.
This commit is contained in:
@@ -36,7 +36,7 @@ def get_current_context_name_with_source():
|
||||
json.load(f).get("currentContext", "default"),
|
||||
f"configuration file {docker_cfg_path}",
|
||||
)
|
||||
except Exception:
|
||||
except Exception: # pylint: disable=broad-exception-caught
|
||||
pass
|
||||
return "default", "fallback value"
|
||||
|
||||
@@ -54,7 +54,7 @@ def write_context_name_to_docker_config(name=None):
|
||||
try:
|
||||
with open(docker_cfg_path, "rt", encoding="utf-8") as f:
|
||||
config = json.load(f)
|
||||
except Exception as e:
|
||||
except Exception as e: # pylint: disable=broad-exception-caught
|
||||
return e
|
||||
current_context = config.get("currentContext", None)
|
||||
if current_context and not name:
|
||||
@@ -68,7 +68,7 @@ def write_context_name_to_docker_config(name=None):
|
||||
try:
|
||||
with open(docker_cfg_path, "wt", encoding="utf-8") as f:
|
||||
json.dump(config, f, indent=4)
|
||||
except Exception as e:
|
||||
except Exception as e: # pylint: disable=broad-exception-caught
|
||||
return e
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user