1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-02-04 07:51:50 +00:00

fix ruff cases UP024,UP041 (#11391)

* fix ruff cases UP024,UP041

* add changelog frag
This commit is contained in:
Alexei Znamensky 2026-01-07 05:29:44 +13:00 committed by GitHub
parent d4089ca29a
commit b67c94fc3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 10 additions and 11 deletions

View file

@ -0,0 +1,3 @@
minor_changes:
- wsl connection plugin - replace aliased errors with proper Python error (https://github.com/ansible-collections/community.general/pull/11391).
- nsupdate modules plugin - replace aliased errors with proper Python error (https://github.com/ansible-collections/community.general/pull/11391).

View file

@ -312,7 +312,6 @@ import io
import os
import pathlib
import shlex
import socket
import tempfile
import traceback
import typing as t
@ -667,7 +666,7 @@ class Connection(ConnectionBase):
elif in_data == b"":
chan.shutdown_write()
except socket.timeout as e:
except TimeoutError as e:
raise AnsibleError(f"ssh timed out waiting for privilege escalation.\n{to_text(become_output)}") from e
stdout = b"".join(chan.makefile("rb", bufsize))

View file

@ -182,7 +182,6 @@ dns_rc_str:
import traceback
from binascii import Error as binascii_error
from socket import error as socket_error
DNSPYTHON_IMP_ERR = None
try:
@ -263,7 +262,7 @@ class RecordManager:
)
except (dns.tsig.PeerBadKey, dns.tsig.PeerBadSignature) as e:
self.module.fail_json(msg=f"TSIG update error ({e.__class__.__name__}): {e}")
except (socket_error, dns.exception.Timeout) as e:
except (OSError, dns.exception.Timeout) as e:
self.module.fail_json(msg=f"DNS server error: ({e.__class__.__name__}): {e}")
if lookup.rcode() in [dns.rcode.SERVFAIL, dns.rcode.REFUSED]:
self.module.fail_json(
@ -298,7 +297,7 @@ class RecordManager:
)
except (dns.tsig.PeerBadKey, dns.tsig.PeerBadSignature) as e:
self.module.fail_json(msg=f"TSIG update error ({e.__class__.__name__}): {e}")
except (socket_error, dns.exception.Timeout) as e:
except (OSError, dns.exception.Timeout) as e:
self.module.fail_json(msg=f"DNS server error: ({e.__class__.__name__}): {e}")
return response
@ -367,7 +366,7 @@ class RecordManager:
)
except (dns.tsig.PeerBadKey, dns.tsig.PeerBadSignature) as e:
self.module.fail_json(msg=f"TSIG update error ({e.__class__.__name__}): {e}")
except (socket_error, dns.exception.Timeout) as e:
except (OSError, dns.exception.Timeout) as e:
self.module.fail_json(msg=f"DNS server error: ({e.__class__.__name__}): {e}")
lookup_result = lookup.answer[0] if lookup.answer else lookup.authority[0]
@ -458,7 +457,7 @@ class RecordManager:
lookup = dns.query.udp(query, self.module.params["server"], timeout=10, port=self.module.params["port"])
except (dns.tsig.PeerBadKey, dns.tsig.PeerBadSignature) as e:
self.module.fail_json(msg=f"TSIG update error ({e.__class__.__name__}): {e}")
except (socket_error, dns.exception.Timeout) as e:
except (OSError, dns.exception.Timeout) as e:
self.module.fail_json(msg=f"DNS server error: ({e.__class__.__name__}): {e}")
if lookup.rcode() != dns.rcode.NOERROR:

View file

@ -21,8 +21,6 @@ ignore = [
"B905", # zip-without-explicit-strict - needs Python 3.10+
"UP045", # Use `X | None` for type annotations - needs Python 3.10+
# To fix:
"UP024", # Replace aliased errors with `OSError`
"UP041", # Replace aliased errors with `TimeoutError`
"B026", # star-arg-unpacking-after-keyword-arg
"SIM102", # collapsible-if
"SIM114", # if-with-same-arms

View file

@ -255,7 +255,7 @@ def test_read_privateKey_handles_file_read_error():
module = MagicMock()
module.params = {"private_key_path": "/invalid/path.pem"}
with patch("builtins.open", side_effect=IOError("cannot read file")):
with patch("builtins.open", side_effect=OSError("cannot read file")):
jenkins_credential.read_privateKey(module)
module.fail_json.assert_called_once()
@ -286,7 +286,7 @@ def test_embed_file_into_body_fails_when_file_unreadable():
file_path = "/fake/path/missing.pem"
credentials = {"id": "something"}
with patch("builtins.open", side_effect=IOError("can't read file")):
with patch("builtins.open", side_effect=OSError("can't read file")):
jenkins_credential.embed_file_into_body(module, file_path, credentials)
module.fail_json.assert_called_once()