1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-05-02 08:22:52 +00:00

[PR #11341/5b5f7e9e backport][stable-12] batch 1 - update Python idiom to 3.7 using pyupgrade (#11349)

batch 1 - update Python idiom to 3.7 using pyupgrade (#11341)

* batch 1 - update Python idiom to 3.7 using pyupgrade

* add changelog frag

* add changelog frag

(cherry picked from commit 5b5f7e9e64)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2025-12-30 16:47:11 +01:00 committed by GitHub
parent 41f815be57
commit 2d07481e64
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 48 additions and 29 deletions

View file

@ -197,7 +197,7 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
data = self.cobbler.get_profiles(self.token)
else:
data = self.cobbler.get_profiles()
except (socket.gaierror, socket.error, xmlrpc_client.ProtocolError):
except (socket.gaierror, OSError, xmlrpc_client.ProtocolError):
self._reload_cache()
else:
self._init_cache()
@ -221,7 +221,7 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
data[i] = self.cobbler.get_system_as_rendered(host["name"], self.token)
else:
data[i] = self.cobbler.get_system_as_rendered(host["name"])
except (socket.gaierror, socket.error, xmlrpc_client.ProtocolError):
except (socket.gaierror, OSError, xmlrpc_client.ProtocolError):
self._reload_cache()
else:
self._init_cache()

View file

@ -203,7 +203,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
ips += [instance.ips.ipv6.slaac, instance.ips.ipv6.link_local]
ips += instance.ips.ipv6.pools
for ip_type in set(ip.type for ip in ips):
for ip_type in {ip.type for ip in ips}:
self.inventory.set_variable(
hostname, ip_type, make_unsafe(self._ip_data([ip for ip in ips if ip.type == ip_type]))
)

View file

@ -210,9 +210,9 @@ class InventoryModule(BaseInventoryPlugin):
Returns:
dict(json_data): json data"""
try:
with open(path, "r") as json_file:
with open(path) as json_file:
return json.load(json_file)
except (IOError, json.decoder.JSONDecodeError) as err:
except (OSError, json.decoder.JSONDecodeError) as err:
raise AnsibleParserError(f"Could not load the test data from {to_native(path)}: {err}") from err
def save_json_data(self, path, file_name=None):
@ -242,7 +242,7 @@ class InventoryModule(BaseInventoryPlugin):
cwd = os.path.abspath(os.path.dirname(__file__))
with open(os.path.abspath(os.path.join(cwd, *path)), "w") as json_file:
json.dump(self.data, json_file)
except IOError as err:
except OSError as err:
raise AnsibleParserError(f"Could not save data: {err}") from err
def verify_file(self, path):

View file

@ -119,10 +119,10 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
if authfile is None:
authfile = os.path.join(os.environ.get("HOME"), ".one", "one_auth")
try:
with open(authfile, "r") as fp:
with open(authfile) as fp:
authstring = fp.read().rstrip()
username, password = authstring.split(":")
except (OSError, IOError) as e:
except OSError as e:
raise AnsibleError(f"Could not find or read ONE_AUTH file at '{authfile}'") from e
except Exception as e:
raise AnsibleError(f"Error occurs when reading ONE_AUTH file at '{authfile}'") from e