From 4ae9e63d3dfac457fadf7b550cada38cc57901eb Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Tue, 23 Jul 2024 18:35:39 -0700 Subject: [PATCH] Fix miscellaneous lint from increased ruff settings. --- dns/query.py | 2 +- dns/rdtypes/ANY/HIP.py | 2 +- dns/rdtypes/util.py | 2 +- dns/resolver.py | 2 +- dns/win32util.py | 6 +++--- dns/zonefile.py | 2 +- pyproject.toml | 27 ++++++++++++++++++++++++++- 7 files changed, 34 insertions(+), 9 deletions(-) diff --git a/dns/query.py b/dns/query.py index f3907c6f..8f8f97cd 100644 --- a/dns/query.py +++ b/dns/query.py @@ -1601,7 +1601,7 @@ def xfr( raise NotImplementedError # pragma: no cover def writer(self, replacement: bool = False) -> dns.transaction.Transaction: - class DummyTransaction(object): + class DummyTransaction: def nop(self, *args, **kw): pass diff --git a/dns/rdtypes/ANY/HIP.py b/dns/rdtypes/ANY/HIP.py index 91669139..f3157da7 100644 --- a/dns/rdtypes/ANY/HIP.py +++ b/dns/rdtypes/ANY/HIP.py @@ -48,7 +48,7 @@ class HIP(dns.rdata.Rdata): for server in self.servers: servers.append(server.choose_relativity(origin, relativize)) if len(servers) > 0: - text += " " + " ".join((x.to_unicode() for x in servers)) + text += " " + " ".join(x.to_unicode() for x in servers) return "%u %s %s%s" % (self.algorithm, hit, key, text) @classmethod diff --git a/dns/rdtypes/util.py b/dns/rdtypes/util.py index 54908fdc..653a0bf2 100644 --- a/dns/rdtypes/util.py +++ b/dns/rdtypes/util.py @@ -231,7 +231,7 @@ def weighted_processing_order(iterable): total = sum(rdata._processing_weight() or _no_weight for rdata in rdatas) while len(rdatas) > 1: r = random.uniform(0, total) - for n, rdata in enumerate(rdatas): + for n, rdata in enumerate(rdatas): # noqa: B007 weight = rdata._processing_weight() or _no_weight if weight > r: break diff --git a/dns/resolver.py b/dns/resolver.py index f08f824d..1358c4c0 100644 --- a/dns/resolver.py +++ b/dns/resolver.py @@ -1926,7 +1926,7 @@ def _getnameinfo(sockaddr, flags=0): family = socket.AF_INET tuples = _getaddrinfo(host, port, family, socket.SOCK_STREAM, socket.SOL_TCP, 0) if len(tuples) > 1: - raise socket.error("sockaddr resolved to multiple addresses") + raise OSError("sockaddr resolved to multiple addresses") addr = tuples[0][4][0] if flags & socket.NI_DGRAM: pname = "udp" diff --git a/dns/win32util.py b/dns/win32util.py index aaa7e93e..d92eb2dc 100644 --- a/dns/win32util.py +++ b/dns/win32util.py @@ -13,8 +13,8 @@ if sys.platform == "win32": # Keep pylint quiet on non-windows. try: - WindowsError is None # pylint: disable=used-before-assignment - except KeyError: + _ = WindowsError # pylint: disable=used-before-assignment + except NameError: WindowsError = Exception if dns._features.have("wmi"): @@ -232,7 +232,7 @@ if sys.platform == "win32": self._config_fromkey(key, False) finally: key.Close() - except EnvironmentError: + except OSError: break finally: interfaces.Close() diff --git a/dns/zonefile.py b/dns/zonefile.py index af064e73..1836adf1 100644 --- a/dns/zonefile.py +++ b/dns/zonefile.py @@ -528,7 +528,7 @@ class Reader: self.default_ttl_known, ) ) - self.current_file = open(filename, "r") + self.current_file = open(filename) self.tok = dns.tokenizer.Tokenizer(self.current_file, filename) self.current_origin = new_origin elif c == "$GENERATE": diff --git a/pyproject.toml b/pyproject.toml index e4388e47..42827422 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -90,7 +90,32 @@ path = "dns/version.py" expression = "version" [tool.ruff] -lint.ignore = ['E741', 'F401'] +lint.select = [ + # pycodestyle + "E", + # Pyflakes + "F", + # pyupgrade + "UP", + # flake8-bugbear + "B", + # flake8-simplify + #"SIM", + # isort + "I", +] +lint.ignore = [ + "E501", + "E741", + "F401", + "I001", + "SIM102", + "B904", + "B011", + "UP031", + "UP032", +] +lint.exclude = ["tests/*"] [tool.isort] profile = "black" -- 2.47.3