]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
pylint linting
authorBob Halley <halley@dnspython.org>
Fri, 31 Jul 2020 23:03:09 +0000 (16:03 -0700)
committerBob Halley <halley@dnspython.org>
Fri, 31 Jul 2020 23:03:09 +0000 (16:03 -0700)
17 files changed:
Makefile
dns/_asyncio_backend.py
dns/_curio_backend.py
dns/_trio_backend.py
dns/asyncbackend.py
dns/asyncresolver.py
dns/dnssec.py
dns/ipv6.py
dns/message.py
dns/name.py
dns/query.py
dns/rdataset.py
dns/rdtypes/CH/A.py
dns/resolver.py
dns/rrset.py
dns/zone.py
pylintrc

index d961e76f61bc92afc871c588b232d319d115d4ad..ff5115015e4ffdae454fd076438a675354593ac4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -58,6 +58,9 @@ potestlf:
 potype:
        poetry run python -m mypy examples tests dns/*.py
 
+polint:
+       poetry run pylint dns/*.py
+
 poflake:
        poetry run flake8 dns
 
index 3af34ff89cc4a7def762a3c0e8a6db98da5e8707..1cf15192fc402a6f6f476c9e0b9883181929a714 100644 (file)
@@ -86,14 +86,12 @@ class StreamSocket(dns._asyncbackend.DatagramSocket):
         self.writer = writer
 
     async def sendall(self, what, timeout):
-        self.writer.write(what),
+        self.writer.write(what)
         return await _maybe_wait_for(self.writer.drain(), timeout)
-        raise dns.exception.Timeout(timeout=timeout)
 
     async def recv(self, count, timeout):
         return await _maybe_wait_for(self.reader.read(count),
                                      timeout)
-        raise dns.exception.Timeout(timeout=timeout)
 
     async def close(self):
         self.writer.close()
index 300e1b89e409f71d125c69da0b7637ae1891a7e4..894e87c8f8dc08d9222496e854913cc04d53f256 100644 (file)
@@ -21,6 +21,8 @@ def _maybe_timeout(timeout):
 # for brevity
 _lltuple = dns.inet.low_level_address_tuple
 
+# pylint: disable=redefined-outer-name
+
 
 class DatagramSocket(dns._asyncbackend.DatagramSocket):
     def __init__(self, socket):
index 92ea87960cd9a042fc6755fd86807abac92b5fa0..82512cdbcba349247f873cfcff1a0b363d8a4a80 100644 (file)
@@ -21,6 +21,8 @@ def _maybe_timeout(timeout):
 # for brevity
 _lltuple = dns.inet.low_level_address_tuple
 
+# pylint: disable=redefined-outer-name
+
 
 class DatagramSocket(dns._asyncbackend.DatagramSocket):
     def __init__(self, socket):
index 9582a6f8120e5f10336411648cd3ce989681ae91..e6a42ce05c519560c3eeccd197e31001f4c66819 100644 (file)
@@ -2,9 +2,12 @@
 
 import dns.exception
 
+# pylint: disable=unused-import
+
 from dns._asyncbackend import Socket, DatagramSocket, \
     StreamSocket, Backend  # noqa:
 
+# pylint: enable=unused-import
 
 _default_backend = None
 
@@ -25,6 +28,7 @@ def get_backend(name):
 
     Raises NotImplementError if an unknown backend name is specified.
     """
+    # pylint: disable=import-outside-toplevel,redefined-outer-name
     backend = _backends.get(name)
     if backend:
         return backend
@@ -50,6 +54,7 @@ def sniff():
     Returns the name of the library, or raises AsyncLibraryNotFoundError
     if the library cannot be determined.
     """
+    # pylint: disable=import-outside-toplevel
     try:
         if _no_sniffio:
             raise ImportError
index b0af934c5f65d21d141721ffe0ae6e606e1bcdf3..a6582b2af9a06811c325b26e164243ef9b944c51 100644 (file)
@@ -36,6 +36,8 @@ _tcp = dns.asyncquery.tcp
 
 class Resolver(dns.resolver.Resolver):
 
+    # pylint: disable=invalid-overridden-method, arguments-differ
+
     async def resolve(self, qname, rdtype=dns.rdatatype.A,
                       rdclass=dns.rdataclass.IN,
                       tcp=False, source=None, raise_on_no_answer=True,
@@ -139,11 +141,15 @@ class Resolver(dns.resolver.Resolver):
                 if answer is not None:
                     return answer
 
+    # pylint: disable=signature-differs
+
     async def query(self, *args, **kwargs):
         # We have to define something here as we don't want to inherit the
         # parent's query().
         raise NotImplementedError
 
+    # pylint: enable=signature-differs
+
     async def resolve_address(self, ipaddr, *args, **kwargs):
         """Use an asynchronous resolver to run a reverse query for PTR
         records.
@@ -165,6 +171,8 @@ class Resolver(dns.resolver.Resolver):
                                   rdclass=dns.rdataclass.IN,
                                   *args, **kwargs)
 
+    # pylint: disable=redefined-outer-name
+
     async def canonical_name(self, name):
         """Determine the canonical name of *name*.
 
index e36e7293495b00a87404aaef904f81e4a1a5aad1..891999661dee2d1f75694348772f6dd8ba53bf71 100644 (file)
@@ -551,7 +551,7 @@ def nsec3_hash(domain, salt, iterations, algorithm):
     domain_encoded = domain.canonicalize().to_wire()
 
     digest = hashlib.sha1(domain_encoded + salt_encoded).digest()
-    for i in range(iterations):
+    for _ in range(iterations):
         digest = hashlib.sha1(digest + salt_encoded).digest()
 
     output = base64.b32encode(digest).decode("utf-8")
index 5424fcea20d24e5f862fbd26b211903cde2300e3..0905aaf1a4f970469d95a645f05b7a54771fe799 100644 (file)
@@ -157,7 +157,7 @@ def inet_aton(text, ignore_scope=False):
             if seen_empty:
                 raise dns.exception.SyntaxError
             seen_empty = True
-            for i in range(0, 8 - l + 1):
+            for _ in range(0, 8 - l + 1):
                 canonical.append(b'0000')
         else:
             lc = len(c)
index 52e3819f38cbe9fc92e9753488caea85bceffd7f..1dfb0280fa7c2cf9bd92a318452e82a97ecd1a51 100644 (file)
@@ -699,9 +699,13 @@ class Message:
         # What the caller picked is fine.
         return value
 
+    # pylint: disable=unused-argument
+
     def _parse_rr_header(self, section, name, rdclass, rdtype):
         return (rdclass, rdtype, None, False)
 
+    # pylint: enable=unused-argument
+
     def _parse_special_rr_header(self, section, count, position,
                                  name, rdclass, rdtype):
         if rdtype == dns.rdatatype.OPT:
@@ -811,6 +815,8 @@ def _maybe_import_update():
     # We avoid circular imports by doing this here.  We do it in another
     # function as doing it in _message_factory_from_opcode() makes "dns"
     # a local symbol, and the first line fails :)
+
+    # pylint: disable=redefined-outer-name,import-outside-toplevel,unused-import
     import dns.update  # noqa: F401
 
 
@@ -857,7 +863,7 @@ class _WireReader:
         """
 
         section = self.message.sections[section_number]
-        for i in range(qcount):
+        for _ in range(qcount):
             qname = self.parser.get_name(self.message.origin)
             (rdtype, rdclass) = self.parser.get_struct('!HH')
             (rdclass, rdtype, _, _) = \
@@ -1080,7 +1086,7 @@ class _TextReader:
         self.opcode = dns.opcode.QUERY
         self.flags = 0
 
-    def _header_line(self, section):
+    def _header_line(self, _):
         """Process one line from the text format header section."""
 
         token = self.tok.get()
index 94d7b936055bbcb288b512029289d0ca726cffcd..8775e0b8b3fe38cd0694e68f2923215909b05a91 100644 (file)
@@ -459,7 +459,7 @@ class Name:
         Returns a ``bool``.
         """
 
-        (nr, o, nl) = self.fullcompare(other)
+        (nr, _, _) = self.fullcompare(other)
         if nr == NAMERELN_SUBDOMAIN or nr == NAMERELN_EQUAL:
             return True
         return False
@@ -473,7 +473,7 @@ class Name:
         Returns a ``bool``.
         """
 
-        (nr, o, nl) = self.fullcompare(other)
+        (nr, _, _) = self.fullcompare(other)
         if nr == NAMERELN_SUPERDOMAIN or nr == NAMERELN_EQUAL:
             return True
         return False
index c2f619cf7208f871059044456e597f6f247dba75..d4a3afadcea841b3f927d9ec82aef64142f2f0e7 100644 (file)
@@ -95,10 +95,13 @@ def _compute_times(timeout):
         return (now, now + timeout)
 
 
-def _wait_for(fd, readable, writable, error, expiration):
+def _wait_for(fd, readable, writable, _, expiration):
     # Use the selected selector class to wait for any of the specified
     # events.  An "expiration" absolute time is converted into a relative
     # timeout.
+    #
+    # The unused parameter is 'error', which is always set when
+    # selecting for read or write, and we have no error-only selects.
 
     if readable and isinstance(fd, ssl.SSLSocket) and fd.pending() > 0:
         return True
@@ -278,27 +281,24 @@ def https(q, where, timeout=None, port=443, source=None, source_port=0,
         raise NoDOH  # pragma: no cover
 
     wire = q.to_wire()
-    (af, destination, source) = _destination_and_source(where, port,
-                                                        source, source_port,
-                                                        False)
+    (af, _, source) = _destination_and_source(where, port, source, source_port,
+                                              False)
     transport_adapter = None
     headers = {
         "accept": "application/dns-message"
     }
-    try:
-        where_af = dns.inet.af_for_address(where)
-        if where_af == socket.AF_INET:
+    if af is not None:
+        if af == socket.AF_INET:
             url = 'https://{}:{}{}'.format(where, port, path)
-        elif where_af == socket.AF_INET6:
+        elif af == socket.AF_INET6:
             url = 'https://[{}]:{}{}'.format(where, port, path)
-    except ValueError:
-        if bootstrap_address is not None:
-            split_url = urllib.parse.urlsplit(where)
-            headers['Host'] = split_url.hostname
-            url = where.replace(split_url.hostname, bootstrap_address)
-            transport_adapter = HostHeaderSSLAdapter()
-        else:
-            url = where
+    elif bootstrap_address is not None:
+        split_url = urllib.parse.urlsplit(where)
+        headers['Host'] = split_url.hostname
+        url = where.replace(split_url.hostname, bootstrap_address)
+        transport_adapter = HostHeaderSSLAdapter()
+    else:
+        url = where
     if source is not None:
         # set source port and source address
         transport_adapter = SourceAddressAdapter(source)
@@ -917,7 +917,7 @@ def xfr(where, zone, rdtype=dns.rdatatype.AXFR, rdclass=dns.rdataclass.IN,
                (expiration is not None and mexpiration > expiration):
                 mexpiration = expiration
             if use_udp:
-                (wire, from_address) = _udp_recv(s, 65535, expiration)
+                (wire, _) = _udp_recv(s, 65535, expiration)
             else:
                 ldata = _net_read(s, 2, mexpiration)
                 (l,) = struct.unpack("!H", ldata)
index 8e70a08cd130be95285a41b750e6f24a1d891a2f..0e47139dfe9e0e38ff4950d6797aa4cd760c3c26 100644 (file)
@@ -87,7 +87,7 @@ class Rdataset(dns.set.Set):
         elif ttl < self.ttl:
             self.ttl = ttl
 
-    def add(self, rd, ttl=None):
+    def add(self, rd, ttl=None):  # pylint: disable=arguments-differ
         """Add the specified rdata to the rdataset.
 
         If the optional *ttl* parameter is supplied, then
index 330fcae8e3dc7c32c62a0e76b88b85e27e8e9ee5..0cb89e216a0241b958c39716846da2877e543b54 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.mxbase
 import struct
 
+import dns.rdtypes.mxbase
+
 class A(dns.rdata.Rdata):
 
     """A record for Chaosnet"""
index 9600c8e23550d579e9a4a518a9b548e36f8e59aa..eba0b448c16e654547d5d05d9b4615f7b00e68e9 100644 (file)
@@ -43,6 +43,7 @@ import dns.reversename
 import dns.tsig
 
 if sys.platform == 'win32':
+    # pylint: disable=import-error
     import winreg
 
 class NXDOMAIN(dns.exception.DNSException):
@@ -50,7 +51,10 @@ class NXDOMAIN(dns.exception.DNSException):
     supp_kwargs = {'qnames', 'responses'}
     fmt = None  # we have our own __str__ implementation
 
-    def _check_kwargs(self, qnames, responses=None):
+    # pylint: disable=arguments-differ
+
+    def _check_kwargs(self, qnames,
+                      responses=None):
         if not isinstance(qnames, (list, tuple, set)):
             raise AttributeError("qnames must be a list, tuple or set")
         if len(qnames) == 0:
@@ -161,6 +165,7 @@ class NoNameservers(dns.exception.DNSException):
     def _fmt_kwargs(self, **kwargs):
         srv_msgs = []
         for err in kwargs['errors']:
+            # pylint: disable=bad-continuation
             srv_msgs.append('Server {} {} port {} answered {}'.format(err[0],
                             'TCP' if err[1] else 'UDP', err[2], err[3]))
         return super()._fmt_kwargs(query=kwargs['request'].question,
@@ -854,34 +859,36 @@ class Resolver:
                 self.search.append(dns.name.from_text(s))
 
     def _config_win32_fromkey(self, key, always_try_domain):
+        # pylint: disable=undefined-variable
+        # (disabled for WindowsError)
         try:
-            servers, rtype = winreg.QueryValueEx(key, 'NameServer')
-        except WindowsError:  # pylint: disable=undefined-variable
+            servers, _ = winreg.QueryValueEx(key, 'NameServer')
+        except WindowsError:  # pragma: no cover
             servers = None
         if servers:
             self._config_win32_nameservers(servers)
         if servers or always_try_domain:
             try:
-                dom, rtype = winreg.QueryValueEx(key, 'Domain')
+                dom, _ = winreg.QueryValueEx(key, 'Domain')
                 if dom:
                     self._config_win32_domain(dom)  # pragma: no cover
             except WindowsError:  # pragma: no cover
                 pass
         else:
             try:
-                servers, rtype = winreg.QueryValueEx(key, 'DhcpNameServer')
+                servers, _ = winreg.QueryValueEx(key, 'DhcpNameServer')
             except WindowsError:  # pragma: no cover
                 servers = None
             if servers:
                 self._config_win32_nameservers(servers)
                 try:
-                    dom, rtype = winreg.QueryValueEx(key, 'DhcpDomain')
+                    dom, _ = winreg.QueryValueEx(key, 'DhcpDomain')
                     if dom:
                         self._config_win32_domain(dom)
                 except WindowsError:  # pragma: no cover
                     pass
         try:
-            search, rtype = winreg.QueryValueEx(key, 'SearchList')
+            search, _ = winreg.QueryValueEx(key, 'SearchList')
         except WindowsError:  # pragma: no cover
             search = None
         if search:  # pragma: no cover
@@ -909,6 +916,7 @@ class Resolver:
                     try:
                         guid = winreg.EnumKey(interfaces, i)
                         i += 1
+                        # XXXRTH why do we get this key and then not use it?
                         key = winreg.OpenKey(interfaces, guid)
                         if not self._win32_is_nic_enabled(lm, guid, key):
                             continue
@@ -923,8 +931,7 @@ class Resolver:
         finally:
             lm.Close()
 
-    def _win32_is_nic_enabled(self, lm, guid,
-                              interface_key):
+    def _win32_is_nic_enabled(self, lm, guid, _):
         # Look in the Windows Registry to determine whether the network
         # interface corresponding to the given guid is enabled.
         #
@@ -1027,7 +1034,7 @@ class Resolver:
 
     def resolve(self, qname, rdtype=dns.rdatatype.A, rdclass=dns.rdataclass.IN,
                 tcp=False, source=None, raise_on_no_answer=True, source_port=0,
-                lifetime=None, search=None):
+                lifetime=None, search=None):  # pylint: disable=arguments-differ
         """Query nameservers to find the answer to the question.
 
         The *qname*, *rdtype*, and *rdclass* parameters may be objects
@@ -1165,6 +1172,8 @@ class Resolver:
                             rdclass=dns.rdataclass.IN,
                             *args, **kwargs)
 
+    # pylint: disable=redefined-outer-name
+
     def canonical_name(self, name):
         """Determine the canonical name of *name*.
 
@@ -1186,6 +1195,8 @@ class Resolver:
             canonical_name = e.canonical_name
         return canonical_name
 
+    # pylint: enable=redefined-outer-name
+
     def use_tsig(self, keyring, keyname=None,
                  algorithm=dns.tsig.default_algorithm):
         """Add a TSIG signature to each query.
@@ -1405,7 +1416,7 @@ def _getaddrinfo(host=None, service=None, family=socket.AF_UNSPEC, socktype=0,
         raise socket.gaierror(socket.EAI_NONAME, 'Name or service not known')
     v6addrs = []
     v4addrs = []
-    canonical_name = None
+    canonical_name = None  # pylint: disable=redefined-outer-name
     # Is host None or an address literal?  If so, use the system's
     # getaddrinfo().
     if host is None:
@@ -1571,7 +1582,7 @@ def _gethostbyaddr(ip):
                                   'Name or service not known')
         sockaddr = (ip, 80)
         family = socket.AF_INET
-    (name, port) = _getnameinfo(sockaddr, socket.NI_NAMEREQD)
+    (name, _) = _getnameinfo(sockaddr, socket.NI_NAMEREQD)
     aliases = []
     addresses = []
     tuples = _getaddrinfo(name, 0, family, socket.SOCK_STREAM, socket.SOL_TCP,
index 68136f4075c4b494cc6e6945201bbd358d16c30c..13737d3d82fe79d597adc09cf33b74bebf354e99 100644 (file)
@@ -69,13 +69,17 @@ class RRset(dns.rdataset.Rdataset):
         return self.to_text()
 
     def __eq__(self, other):
-        if not isinstance(other, RRset):
-            return False
-        if self.name != other.name:
+        if isinstance(other, RRset):
+            if self.name != other.name:
+                return False
+        elif not isinstance(other, dns.rdataset.Rdataset):
             return False
         return super().__eq__(other)
 
-    def match(self, name, rdclass, rdtype, covers, deleting=None):
+    # pylint: disable=arguments-differ
+
+    def match(self, name, rdclass, rdtype, covers,
+              deleting=None):
         """Returns ``True`` if this rrset matches the specified class, type,
         covers, and deletion state.
         """
@@ -86,7 +90,8 @@ class RRset(dns.rdataset.Rdataset):
             return False
         return True
 
-    def to_text(self, origin=None, relativize=True, **kw):
+    def to_text(self, origin=None, relativize=True,
+                **kw):
         """Convert the RRset into DNS master file format.
 
         See ``dns.name.Name.choose_relativity`` for more information
@@ -106,7 +111,8 @@ class RRset(dns.rdataset.Rdataset):
         return super().to_text(self.name, origin, relativize,
                                self.deleting, **kw)
 
-    def to_wire(self, file, compress=None, origin=None, **kw):
+    def to_wire(self, file, compress=None, origin=None,
+                **kw):
         """Convert the RRset to wire format.
 
         All keyword arguments are passed to ``dns.rdataset.to_wire()``; see
@@ -118,6 +124,8 @@ class RRset(dns.rdataset.Rdataset):
         return super().to_wire(self.name, file, compress, origin,
                                self.deleting, **kw)
 
+    # pylint: enable=arguments-differ
+
     def to_rdataset(self):
         """Convert an RRset into an Rdataset.
 
index ad597e9bc6a6cebc168df88362df94f67371c4a9..d5bb30583f94d4f1e73725768d10edd3eaaa775a 100644 (file)
@@ -904,8 +904,10 @@ class _MasterReader:
         # rhs (required)
         rhs = token.value
 
-        lmod, lsign, loffset, lwidth, lbase = self._parse_modify(lhs)
-        rmod, rsign, roffset, rwidth, rbase = self._parse_modify(rhs)
+        # The code currently only supports base 'd', so the last value
+        # in the tuple _parse_modify returns is ignored
+        lmod, lsign, loffset, lwidth, _ = self._parse_modify(lhs)
+        rmod, rsign, roffset, rwidth, _ = self._parse_modify(rhs)
         for i in range(start, stop + 1, step):
             # +1 because bind is inclusive and python is exclusive
 
index 2a7f7187fa4b17901caedc7fdaed7add805d55b7..809d65401f61d8e983ffe43b41a0666c739aa105 100644 (file)
--- a/pylintrc
+++ b/pylintrc
@@ -9,7 +9,6 @@ jobs=0
 
 enable=
     all,
-    python3
 
 # It's worth looking at len-as-condition for optimization, but it's disabled
 # here as it is not a correctness thing.  Similarly eq-without-hash is
@@ -18,36 +17,26 @@ enable=
 disable=
     R,
     I,
-    anomalous-backslash-in-string,
-    arguments-differ,
-    assigning-non-slot,
-    bad-builtin,
-    bad-continuation,
     broad-except,
-    deprecated-method,
     fixme,
     global-statement,
     invalid-name,
-    missing-docstring,
+    missing-module-docstring,
+    missing-class-docstring,
+    missing-function-docstring,
     no-absolute-import,
-    no-member,
+    no-member,  # We'd like to use this, but our immutability is too hard for it
     protected-access,
     redefined-builtin,
     too-many-lines,
-    unused-argument,
-    unused-variable,
-    wrong-import-order,
-    wrong-import-position,
-    len-as-condition,
-    eq-without-hash,
-    next-method-defined,
 
 [REPORTS]
 
 # Set the output format. Available formats are text, parseable, colorized, msvs
 # (visual studio) and html. You can also give a reporter class, eg
 # mypackage.mymodule.MyReporterClass.
-output-format=colorized
+#output-format=colorized
+output-format=parseable
 
 # Tells whether to display a full report or only the messages
 reports=no