From: Bob Halley Date: Thu, 17 Feb 2022 14:51:15 +0000 (-0800) Subject: more lgtm linting X-Git-Tag: v2.3.0rc1~136 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d757cca9217363a560d755889f8efdc06fc2ec5d;p=thirdparty%2Fdnspython.git more lgtm linting --- diff --git a/.flake8 b/.flake8 index 3b1f77de..809116b6 100644 --- a/.flake8 +++ b/.flake8 @@ -18,4 +18,4 @@ ignore = # Lines ending with binary operators are OK W504, -max-line-length = 80 +max-line-length = 120 diff --git a/dns/_curio_backend.py b/dns/_curio_backend.py index 6fa7b3a1..535eb84d 100644 --- a/dns/_curio_backend.py +++ b/dns/_curio_backend.py @@ -32,12 +32,12 @@ class DatagramSocket(dns._asyncbackend.DatagramSocket): async def sendto(self, what, destination, timeout): async with _maybe_timeout(timeout): return await self.socket.sendto(what, destination) - raise dns.exception.Timeout(timeout=timeout) # pragma: no cover + raise dns.exception.Timeout(timeout=timeout) # pragma: no cover lgtm[py/unreachable-statement] async def recvfrom(self, size, timeout): async with _maybe_timeout(timeout): return await self.socket.recvfrom(size) - raise dns.exception.Timeout(timeout=timeout) + raise dns.exception.Timeout(timeout=timeout) # lgtm[py/unreachable-statement] async def close(self): await self.socket.close() @@ -57,12 +57,12 @@ class StreamSocket(dns._asyncbackend.StreamSocket): async def sendall(self, what, timeout): async with _maybe_timeout(timeout): return await self.socket.sendall(what) - raise dns.exception.Timeout(timeout=timeout) + raise dns.exception.Timeout(timeout=timeout) # lgtm[py/unreachable-statement] async def recv(self, size, timeout): async with _maybe_timeout(timeout): return await self.socket.recv(size) - raise dns.exception.Timeout(timeout=timeout) + raise dns.exception.Timeout(timeout=timeout) # lgtm[py/unreachable-statement] async def close(self): await self.socket.close() diff --git a/dns/_trio_backend.py b/dns/_trio_backend.py index 4144313a..863d413e 100644 --- a/dns/_trio_backend.py +++ b/dns/_trio_backend.py @@ -32,12 +32,12 @@ class DatagramSocket(dns._asyncbackend.DatagramSocket): async def sendto(self, what, destination, timeout): with _maybe_timeout(timeout): return await self.socket.sendto(what, destination) - raise dns.exception.Timeout(timeout=timeout) # pragma: no cover + raise dns.exception.Timeout(timeout=timeout) # pragma: no cover lgtm[py/unreachable-statement] async def recvfrom(self, size, timeout): with _maybe_timeout(timeout): return await self.socket.recvfrom(size) - raise dns.exception.Timeout(timeout=timeout) + raise dns.exception.Timeout(timeout=timeout) # lgtm[py/unreachable-statement] async def close(self): self.socket.close() @@ -58,12 +58,12 @@ class StreamSocket(dns._asyncbackend.StreamSocket): async def sendall(self, what, timeout): with _maybe_timeout(timeout): return await self.stream.send_all(what) - raise dns.exception.Timeout(timeout=timeout) + raise dns.exception.Timeout(timeout=timeout) # lgtm[py/unreachable-statement] async def recv(self, size, timeout): with _maybe_timeout(timeout): return await self.stream.receive_some(size) - raise dns.exception.Timeout(timeout=timeout) + raise dns.exception.Timeout(timeout=timeout) # lgtm[py/unreachable-statement] async def close(self): await self.stream.aclose() diff --git a/dns/asyncbackend.py b/dns/asyncbackend.py index 089d3d35..aef14b55 100644 --- a/dns/asyncbackend.py +++ b/dns/asyncbackend.py @@ -5,7 +5,7 @@ import dns.exception # pylint: disable=unused-import from dns._asyncbackend import Socket, DatagramSocket, \ - StreamSocket, Backend # noqa: + StreamSocket, Backend # noqa: F401 lgtm[py/unused-import] # pylint: enable=unused-import diff --git a/dns/asyncquery.py b/dns/asyncquery.py index 4ec97fb7..826b8cfa 100644 --- a/dns/asyncquery.py +++ b/dns/asyncquery.py @@ -330,7 +330,8 @@ async def tls(q, where, timeout=None, port=853, source=None, source_port=0, (begin_time, expiration) = _compute_times(timeout) if not sock: if ssl_context is None: - ssl_context = ssl.create_default_context() + # See the comment about ssl.create_default_context() in query.py + ssl_context = ssl.create_default_context() # lgtm[py/insecure-protocol] if server_hostname is None: ssl_context.check_hostname = False else: diff --git a/dns/asyncresolver.py b/dns/asyncresolver.py index ed29deed..b4837567 100644 --- a/dns/asyncresolver.py +++ b/dns/asyncresolver.py @@ -23,7 +23,7 @@ import dns.asyncbackend import dns.asyncquery import dns.exception import dns.query -import dns.resolver +import dns.resolver # lgtm[py/import-and-import-from] # import some resolver symbols for brevity from dns.resolver import NXDOMAIN, NoAnswer, NotAbsolute, NoRootSOA diff --git a/dns/edns.py b/dns/edns.py index 9d7e909d..fa4e98b1 100644 --- a/dns/edns.py +++ b/dns/edns.py @@ -142,7 +142,7 @@ class Option: return self.to_text() -class GenericOption(Option): +class GenericOption(Option): # lgtm[py/missing-equals] """Generic Option Class @@ -168,7 +168,7 @@ class GenericOption(Option): return cls(otype, parser.get_remaining()) -class ECSOption(Option): +class ECSOption(Option): # lgtm[py/missing-equals] """EDNS Client Subnet (ECS, RFC7871)""" def __init__(self, address, srclen=None, scopelen=0): @@ -334,7 +334,7 @@ class EDECode(dns.enum.IntEnum): return 65535 -class EDEOption(Option): +class EDEOption(Option): # lgtm[py/missing-equals] """Extended DNS Error (EDE, RFC8914)""" def __init__(self, code, text=None): diff --git a/dns/exception.py b/dns/exception.py index 08393821..53764588 100644 --- a/dns/exception.py +++ b/dns/exception.py @@ -51,7 +51,8 @@ class DNSException(Exception): def __init__(self, *args, **kwargs): self._check_params(*args, **kwargs) if kwargs: - self.kwargs = self._check_kwargs(**kwargs) + # This call to a virtual method from __init__ is ok in our usage + self.kwargs = self._check_kwargs(**kwargs) # lgtm[py/init-calls-subclass] self.msg = str(self) else: self.kwargs = dict() # defined but empty for old mode exceptions diff --git a/dns/immutable.py b/dns/immutable.py index db7abbcc..672be598 100644 --- a/dns/immutable.py +++ b/dns/immutable.py @@ -15,7 +15,7 @@ else: @immutable -class Dict(collections.abc.Mapping): +class Dict(collections.abc.Mapping): # lgtm[py/missing-equals] def __init__(self, dictionary, no_copy=False): """Make an immutable dictionary from the specified dictionary. diff --git a/dns/query.py b/dns/query.py index 593601d2..4434ede6 100644 --- a/dns/query.py +++ b/dns/query.py @@ -858,7 +858,13 @@ def tls(q, where, timeout=None, port=853, source=None, source_port=0, (af, destination, source) = _destination_and_source(where, port, source, source_port) if ssl_context is None and not sock: - ssl_context = ssl.create_default_context() + # LGTM complains about this because the default might permit TLS < 1.2 + # for compatibility, but the python documentation says that explicit + # versioning is deprecated. and that as of python 3.6 it will negotiate + # the highest version possible. While we can set a minimum version, + # this isn't great either as we might set it lower than a future + # python version would. + ssl_context = ssl.create_default_context() # lgtm[py/insecure-protocol] if server_hostname is None: ssl_context.check_hostname = False diff --git a/dns/rdataset.py b/dns/rdataset.py index 8a56b066..8da7f2b9 100644 --- a/dns/rdataset.py +++ b/dns/rdataset.py @@ -325,7 +325,7 @@ class Rdataset(dns.set.Set): @dns.immutable.immutable -class ImmutableRdataset(Rdataset): +class ImmutableRdataset(Rdataset): # lgtm[py/missing-equals] """An immutable DNS rdataset.""" diff --git a/dns/rdtypes/ANY/CDNSKEY.py b/dns/rdtypes/ANY/CDNSKEY.py index 14b19417..7ea8f2a9 100644 --- a/dns/rdtypes/ANY/CDNSKEY.py +++ b/dns/rdtypes/ANY/CDNSKEY.py @@ -15,11 +15,11 @@ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -import dns.rdtypes.dnskeybase +import dns.rdtypes.dnskeybase # lgtm[py/import-and-import-from] import dns.immutable # pylint: disable=unused-import -from dns.rdtypes.dnskeybase import SEP, REVOKE, ZONE # noqa: F401 +from dns.rdtypes.dnskeybase import SEP, REVOKE, ZONE # noqa: F401 lgtm[py/unused-import] # pylint: enable=unused-import @dns.immutable.immutable diff --git a/dns/rdtypes/ANY/DNSKEY.py b/dns/rdtypes/ANY/DNSKEY.py index e69a7c19..cc0bf8cf 100644 --- a/dns/rdtypes/ANY/DNSKEY.py +++ b/dns/rdtypes/ANY/DNSKEY.py @@ -15,11 +15,11 @@ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -import dns.rdtypes.dnskeybase +import dns.rdtypes.dnskeybase # lgtm[py/import-and-import-from] import dns.immutable # pylint: disable=unused-import -from dns.rdtypes.dnskeybase import SEP, REVOKE, ZONE # noqa: F401 +from dns.rdtypes.dnskeybase import SEP, REVOKE, ZONE # noqa: F401 lgtm[py/unused-import] # pylint: enable=unused-import @dns.immutable.immutable diff --git a/dns/rdtypes/svcbbase.py b/dns/rdtypes/svcbbase.py index 3362571c..d2874996 100644 --- a/dns/rdtypes/svcbbase.py +++ b/dns/rdtypes/svcbbase.py @@ -433,7 +433,7 @@ class SVCBBase(dns.rdata.Rdata): for k, v in params.items(): k = ParamKey.make(k) if not isinstance(v, Param) and v is not None: - raise ValueError("not a Param") + raise ValueError(f"{k:d} not a Param") self.params = dns.immutable.Dict(params) # Make sure any parameter listed as mandatory is present in the # record. diff --git a/dns/set.py b/dns/set.py index ff1ecc50..32b50a73 100644 --- a/dns/set.py +++ b/dns/set.py @@ -44,7 +44,9 @@ class Set: self.items = odict() if items is not None: for item in items: - self.add(item) + # This is safe for how we use set, but if other code + # subclasses it could be a legitimate issue. + self.add(item) # lgtm[py/init-calls-subclass] def __repr__(self): return "dns.set.Set(%s)" % repr(list(self.items.keys())) @@ -73,7 +75,7 @@ class Set: def pop(self): """Remove an arbitrary item from the set.""" - (k, v) = self.items.popitem() + (k, _) = self.items.popitem() return k def _clone(self): diff --git a/dns/update.py b/dns/update.py index a541af22..9a047553 100644 --- a/dns/update.py +++ b/dns/update.py @@ -39,7 +39,7 @@ class UpdateSection(dns.enum.IntEnum): return 3 -class UpdateMessage(dns.message.Message): +class UpdateMessage(dns.message.Message): # lgtm[py/missing-equals] _section_enum = UpdateSection diff --git a/dns/versioned.py b/dns/versioned.py index 8b6c275f..a7e1204b 100644 --- a/dns/versioned.py +++ b/dns/versioned.py @@ -30,7 +30,7 @@ ImmutableVersion = dns.zone.ImmutableVersion Transaction = dns.zone.Transaction -class Zone(dns.zone.Zone): +class Zone(dns.zone.Zone): # lgtm[py/missing-equals] __slots__ = ['_versions', '_versions_lock', '_write_txn', '_write_waiters', '_write_event', '_pruning_policy', diff --git a/dns/zone.py b/dns/zone.py index 69c3a738..71028ae3 100644 --- a/dns/zone.py +++ b/dns/zone.py @@ -816,7 +816,7 @@ class Zone(dns.transaction.TransactionManager): # A node with a version id. -class VersionedNode(dns.node.Node): +class VersionedNode(dns.node.Node): # lgtm[py/missing-equals] __slots__ = ['id'] def __init__(self): diff --git a/pylintrc b/pylintrc index 6de0fff7..f23e8ea4 100644 --- a/pylintrc +++ b/pylintrc @@ -47,3 +47,6 @@ reports=no # Template used to display messages. This is a python new-style format string # used to format the message information. See doc for all details msg-template='{path}:{line}: [{msg_id}({symbol}), {obj}] {msg})' + +[FORMAT] +max-line-length=120