]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
more lgtm linting
authorBob Halley <halley@dnspython.org>
Thu, 17 Feb 2022 14:51:15 +0000 (06:51 -0800)
committerBob Halley <halley@dnspython.org>
Thu, 17 Feb 2022 14:51:15 +0000 (06:51 -0800)
19 files changed:
.flake8
dns/_curio_backend.py
dns/_trio_backend.py
dns/asyncbackend.py
dns/asyncquery.py
dns/asyncresolver.py
dns/edns.py
dns/exception.py
dns/immutable.py
dns/query.py
dns/rdataset.py
dns/rdtypes/ANY/CDNSKEY.py
dns/rdtypes/ANY/DNSKEY.py
dns/rdtypes/svcbbase.py
dns/set.py
dns/update.py
dns/versioned.py
dns/zone.py
pylintrc

diff --git a/.flake8 b/.flake8
index 3b1f77dece40e07386b80652715c26adfba1c20b..809116b60652160f3fadd310cd555b19a0a03297 100644 (file)
--- 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
index 6fa7b3a17eb4a8853fd20c635a55ce4e0629138a..535eb84d22257c0b0ba4b7b94fd458335c28d46c 100644 (file)
@@ -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()
index 4144313a94ea2713ea17978d2e27f18f334ad0d9..863d413e84ff7dd0177418a74495456f7860733f 100644 (file)
@@ -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()
index 089d3d35027266eba106fe1f6a0ff5fc7c5c7f55..aef14b556cb58fdde1dcc5297e02afd661f81f60 100644 (file)
@@ -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
 
index 4ec97fb7d21852d5e72bf049b257b176b789f86a..826b8cfa8aeeb77609d3959281dbd8ef74c8950f 100644 (file)
@@ -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:
index ed29deed7c95a30a3dace6bb4b1b62953a96ce25..b483756744d451a5746f973a614729b7b7708f9d 100644 (file)
@@ -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
index 9d7e909dbbe767ad905f7e240dfb24c6c77060d0..fa4e98b1d83847bd5ec698e96f55e94b88d862a6 100644 (file)
@@ -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):
index 0839382158c2e47f583e0294db4cfc300791708c..5376458805bbd0d3c5b70ca750c6a5df7a399957 100644 (file)
@@ -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
index db7abbcc13ab933aba6b11860c5b594d2bc16812..672be59847d0601eb3b94856c03eb77ac6522920 100644 (file)
@@ -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.
 
index 593601d2b44d7b2f25db3c8858870e4a45339ce6..4434ede638c6199bf659b9b2ea9ba65a6c7bb753 100644 (file)
@@ -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
 
index 8a56b0669e059518f3a08c42b76bcbe7df0e0d16..8da7f2b9b4b97d5efd3116eadfb0aea9b3857182 100644 (file)
@@ -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."""
 
index 14b19417d7862fc7738f2402d022c0352bf4b029..7ea8f2a99f507e4c72eedd561b8cf7a9d82d39ba 100644 (file)
 # 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
index e69a7c197e8eccb6bc0696d45b03b0b061415968..cc0bf8cf636212ceecdf7248fbd08d2efc4fcc36 100644 (file)
 # 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
index 3362571c46e8aa4e1c67e053280465f4e95c8c01..d28749968928225ef0105934e65df59f4165030a 100644 (file)
@@ -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.
index ff1ecc503a9a741f9d2a4ca1604cc29c75ab0a72..32b50a73686567c2dc612e737891307cfff25424 100644 (file)
@@ -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):
index a541af22db58ce9b37944dcde783fdcebdf1cc5f..9a047553ab594f62d55f15c0cfd04fbbf3f47b91 100644 (file)
@@ -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
 
index 8b6c275fd2398875f2fbd03bfd16aa39ba737bff..a7e1204bbdb89608448fe7d0672866086db5885d 100644 (file)
@@ -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',
index 69c3a73843afec52f3ca0bf0731c216201d4c80f..71028ae3530eb305c8ed021e3c2fa60f1e48199b 100644 (file)
@@ -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):
index 6de0fff781e1161fd8d84bf90e151cb473170c14..f23e8ea4a3bb0c99501054afdd9a8fe69cd8c145 100644 (file)
--- 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