Skip to content

Commit

Permalink
Remove useless pylint error suppression directives (#7657)
Browse files Browse the repository at this point in the history
As pylint is evolving, it improves its accuracy, and several pylint error suppression (`# pylint: disable=ERROR) added in certbot codebase months or years ago are not needed anymore to make it happy.

There is a (disabled by default) pylint error to detect the useless suppressions (pylint-ception: `useless-suppression`). It is not working perfectly (it has also false-positives ...) but it is a good start to clean the codebase.

This PR removes several of these useless suppressions as detected by the current pylint version we use.

* Remove useless suppress

* Remove useless lines
  • Loading branch information
adferrand committed Feb 13, 2020
1 parent bcaee66 commit fc7e5e8
Show file tree
Hide file tree
Showing 71 changed files with 183 additions and 202 deletions.
2 changes: 1 addition & 1 deletion acme/acme/challenges.py
Expand Up @@ -54,7 +54,7 @@ def __init__(self, jobj):
object.__setattr__(self, "jobj", jobj)

def to_partial_json(self):
return self.jobj # pylint: disable=no-member
return self.jobj

@classmethod
def from_json(cls, jobj):
Expand Down
14 changes: 7 additions & 7 deletions acme/acme/client.py
Expand Up @@ -15,16 +15,16 @@
from requests.adapters import HTTPAdapter
from requests_toolbelt.adapters.source import SourceAddressAdapter
import six
from six.moves import http_client # pylint: disable=import-error
from six.moves import http_client

from acme import crypto_util
from acme import errors
from acme import jws
from acme import messages
from acme.magic_typing import Dict # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import List # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import Set # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import Text # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import Dict
from acme.magic_typing import List
from acme.magic_typing import Set
from acme.magic_typing import Text

logger = logging.getLogger(__name__)

Expand All @@ -36,7 +36,7 @@
try:
requests.packages.urllib3.contrib.pyopenssl.inject_into_urllib3() # type: ignore
except AttributeError:
import urllib3.contrib.pyopenssl # pylint: disable=import-error
import urllib3.contrib.pyopenssl
urllib3.contrib.pyopenssl.inject_into_urllib3()

DEFAULT_NETWORK_TIMEOUT = 45
Expand Down Expand Up @@ -666,7 +666,7 @@ def new_order(self, csr_pem):
response = self._post(self.directory['newOrder'], order)
body = messages.Order.from_json(response.json())
authorizations = []
for url in body.authorizations: # pylint: disable=not-an-iterable
for url in body.authorizations:
authorizations.append(self._authzr_from_response(self._post_as_get(url), uri=url))
return messages.OrderResource(
body=body,
Expand Down
12 changes: 5 additions & 7 deletions acme/acme/crypto_util.py
Expand Up @@ -11,10 +11,9 @@
from OpenSSL import SSL # type: ignore # https://github.com/python/typeshed/issues/2052

from acme import errors
from acme.magic_typing import Callable # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import Optional # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import Tuple # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import Union # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import Callable
from acme.magic_typing import Tuple
from acme.magic_typing import Union

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -74,7 +73,7 @@ def _pick_certificate_cb(self, connection):
class FakeConnection(object):
"""Fake OpenSSL.SSL.Connection."""

# pylint: disable=missing-docstring
# pylint: disable=missing-function-docstring

def __init__(self, connection):
self._wrapped = connection
Expand All @@ -86,7 +85,7 @@ def shutdown(self, *unused_args):
# OpenSSL.SSL.Connection.shutdown doesn't accept any args
return self._wrapped.shutdown()

def accept(self): # pylint: disable=missing-docstring
def accept(self): # pylint: disable=missing-function-docstring
sock, addr = self.sock.accept()

context = SSL.Context(self.method)
Expand Down Expand Up @@ -298,7 +297,6 @@ def dump_pyopenssl_chain(chain, filetype=crypto.FILETYPE_PEM):

def _dump_cert(cert):
if isinstance(cert, jose.ComparableX509):
# pylint: disable=protected-access
cert = cert.wrapped
return crypto.dump_certificate(filetype, cert)

Expand Down
4 changes: 2 additions & 2 deletions acme/acme/jws.py
Expand Up @@ -15,7 +15,7 @@ class Header(jose.Header):
url = jose.Field('url', omitempty=True)

@nonce.decoder
def nonce(value): # pylint: disable=missing-docstring,no-self-argument
def nonce(value): # pylint: disable=no-self-argument,missing-function-docstring
try:
return jose.decode_b64jose(value)
except jose.DeserializationError as error:
Expand All @@ -25,7 +25,7 @@ def nonce(value): # pylint: disable=missing-docstring,no-self-argument

class Signature(jose.Signature):
"""ACME-specific Signature. Uses ACME-specific Header for customer fields."""
__slots__ = jose.Signature._orig_slots # pylint: disable=no-member
__slots__ = jose.Signature._orig_slots

# TODO: decoder/encoder should accept cls? Otherwise, subclassing
# JSONObjectWithFields is tricky...
Expand Down
1 change: 0 additions & 1 deletion acme/acme/magic_typing.py
Expand Up @@ -10,7 +10,6 @@ def __getattr__(self, name):
try:
# mypy doesn't respect modifying sys.modules
from typing import * # pylint: disable=wildcard-import, unused-wildcard-import
# pylint: disable=unused-import
from typing import Collection, IO # type: ignore
# pylint: enable=unused-import
except ImportError:
Expand Down
7 changes: 3 additions & 4 deletions acme/acme/messages.py
Expand Up @@ -11,7 +11,7 @@
from acme import util

try:
from collections.abc import Hashable # pylint: disable=no-name-in-module
from collections.abc import Hashable
except ImportError: # pragma: no cover
from collections import Hashable

Expand Down Expand Up @@ -460,7 +460,6 @@ class ChallengeResource(Resource):
@property
def uri(self):
"""The URL of the challenge body."""
# pylint: disable=function-redefined,no-member
return self.body.uri


Expand Down Expand Up @@ -488,7 +487,7 @@ class Authorization(ResourceBody):
wildcard = jose.Field('wildcard', omitempty=True)

@challenges.decoder
def challenges(value): # pylint: disable=missing-docstring,no-self-argument
def challenges(value): # pylint: disable=no-self-argument,missing-function-docstring
return tuple(ChallengeBody.from_json(chall) for chall in value)

@property
Expand Down Expand Up @@ -585,7 +584,7 @@ class Order(ResourceBody):
error = jose.Field('error', omitempty=True, decoder=Error.from_json)

@identifiers.decoder
def identifiers(value): # pylint: disable=missing-docstring,no-self-argument
def identifiers(value): # pylint: disable=no-self-argument,missing-function-docstring
return tuple(Identifier.from_json(identifier) for identifier in value)

class OrderResource(ResourceWithURI):
Expand Down
16 changes: 6 additions & 10 deletions acme/acme/standalone.py
Expand Up @@ -5,19 +5,16 @@
import socket
import threading

from six.moves import BaseHTTPServer # type: ignore # pylint: disable=import-error
from six.moves import http_client # pylint: disable=import-error
from six.moves import socketserver # type: ignore # pylint: disable=import-error
from six.moves import BaseHTTPServer # type: ignore
from six.moves import http_client
from six.moves import socketserver # type: ignore

from acme import challenges
from acme import crypto_util
from acme.magic_typing import List # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import List

logger = logging.getLogger(__name__)

# six.moves.* | pylint: disable=no-member,attribute-defined-outside-init
# pylint: disable=no-init


class TLSServer(socketserver.TCPServer):
"""Generic TLS Server."""
Expand All @@ -30,7 +27,6 @@ def __init__(self, *args, **kwargs):
self.address_family = socket.AF_INET
self.certs = kwargs.pop("certs", {})
self.method = kwargs.pop(
# pylint: disable=protected-access
"method", crypto_util._DEFAULT_SSL_METHOD)
self.allow_reuse_address = kwargs.pop("allow_reuse_address", True)
socketserver.TCPServer.__init__(self, *args, **kwargs)
Expand All @@ -39,7 +35,7 @@ def _wrap_sock(self):
self.socket = crypto_util.SSLSocket(
self.socket, certs=self.certs, method=self.method)

def server_bind(self): # pylint: disable=missing-docstring
def server_bind(self):
self._wrap_sock()
return socketserver.TCPServer.server_bind(self)

Expand Down Expand Up @@ -178,7 +174,7 @@ def handle(self):
self.log_message("Incoming request")
BaseHTTPServer.BaseHTTPRequestHandler.handle(self)

def do_GET(self): # pylint: disable=invalid-name,missing-docstring
def do_GET(self): # pylint: disable=invalid-name,missing-function-docstring
if self.path == "/":
self.handle_index()
elif self.path.startswith("/" + challenges.HTTP01.URI_ROOT_PATH):
Expand Down
20 changes: 10 additions & 10 deletions certbot-apache/certbot_apache/_internal/configurator.py
Expand Up @@ -14,11 +14,11 @@
import zope.interface

from acme import challenges
from acme.magic_typing import DefaultDict # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import Dict # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import List # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import Set # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import Union # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import DefaultDict
from acme.magic_typing import Dict
from acme.magic_typing import List
from acme.magic_typing import Set
from acme.magic_typing import Union
from certbot import errors
from certbot import interfaces
from certbot import util
Expand Down Expand Up @@ -792,7 +792,7 @@ def get_all_names(self):

return util.get_filtered_names(all_names)

def get_name_from_ip(self, addr): # pylint: disable=no-self-use
def get_name_from_ip(self, addr):
"""Returns a reverse dns name if available.
:param addr: IP Address
Expand Down Expand Up @@ -1726,7 +1726,7 @@ def _escape(self, fp):
######################################################################
# Enhancements
######################################################################
def supported_enhancements(self): # pylint: disable=no-self-use
def supported_enhancements(self):
"""Returns currently supported enhancements."""
return ["redirect", "ensure-http-header", "staple-ocsp"]

Expand Down Expand Up @@ -2292,7 +2292,7 @@ def enable_site(self, vhost):
vhost.enabled = True
return

def enable_mod(self, mod_name, temp=False): # pylint: disable=unused-argument
def enable_mod(self, mod_name, temp=False):
"""Enables module in Apache.
Both enables and reloads Apache so module is active.
Expand Down Expand Up @@ -2350,7 +2350,7 @@ def _reload(self):
error = str(err)
raise errors.MisconfigurationError(error)

def config_test(self): # pylint: disable=no-self-use
def config_test(self):
"""Check the configuration of Apache for errors.
:raises .errors.MisconfigurationError: If config_test fails
Expand Down Expand Up @@ -2400,7 +2400,7 @@ def more_info(self):
###########################################################################
# Challenges Section
###########################################################################
def get_chall_pref(self, unused_domain): # pylint: disable=no-self-use
def get_chall_pref(self, unused_domain):
"""Return list of challenge preferences."""
return [challenges.HTTP01]

Expand Down
2 changes: 1 addition & 1 deletion certbot-apache/certbot_apache/_internal/entrypoint.py
@@ -1,7 +1,7 @@
""" Entry point for Apache Plugin """
# Pylint does not like disutils.version when running inside a venv.
# See: https://github.com/PyCQA/pylint/issues/73
from distutils.version import LooseVersion # pylint: disable=no-name-in-module,import-error
from distutils.version import LooseVersion

from certbot import util
from certbot_apache._internal import configurator
Expand Down
4 changes: 2 additions & 2 deletions certbot-apache/certbot_apache/_internal/http_01.py
@@ -1,8 +1,8 @@
"""A class that performs HTTP-01 challenges for Apache"""
import logging

from acme.magic_typing import List # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import Set # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import List
from acme.magic_typing import Set
from certbot import errors
from certbot.compat import filesystem
from certbot.compat import os
Expand Down
2 changes: 1 addition & 1 deletion certbot-apache/certbot_apache/_internal/obj.py
@@ -1,7 +1,7 @@
"""Module contains classes used by the Apache Configurator."""
import re

from acme.magic_typing import Set # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import Set
from certbot.plugins import common


Expand Down
2 changes: 1 addition & 1 deletion certbot-apache/certbot_apache/_internal/override_centos.py
Expand Up @@ -4,7 +4,7 @@
import pkg_resources
import zope.interface

from acme.magic_typing import List # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import List
from certbot import errors
from certbot import interfaces
from certbot import util
Expand Down
10 changes: 5 additions & 5 deletions certbot-apache/certbot_apache/_internal/parser.py
Expand Up @@ -7,9 +7,9 @@

import six

from acme.magic_typing import Dict # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import List # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import Set # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import Dict
from acme.magic_typing import List
from acme.magic_typing import Set
from certbot import errors
from certbot.compat import os
from certbot_apache._internal import apache_util
Expand Down Expand Up @@ -321,7 +321,7 @@ def update_modules(self):
for mod in matches:
self.add_mod(mod.strip())

def filter_args_num(self, matches, args): # pylint: disable=no-self-use
def filter_args_num(self, matches, args):
"""Filter out directives with specific number of arguments.
This function makes the assumption that all related arguments are given
Expand Down Expand Up @@ -715,7 +715,7 @@ def _get_include_path(self, arg):

return get_aug_path(arg)

def fnmatch_to_re(self, clean_fn_match): # pylint: disable=no-self-use
def fnmatch_to_re(self, clean_fn_match):
"""Method converts Apache's basic fnmatch to regular expression.
Assumption - Configs are assumed to be well-formed and only writable by
Expand Down
Expand Up @@ -5,7 +5,7 @@

import zope.interface

from acme.magic_typing import Set # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import Set
from certbot._internal import configuration
from certbot_compatibility_test import errors
from certbot_compatibility_test import interfaces
Expand Down
Expand Up @@ -15,8 +15,8 @@
from acme import challenges
from acme import crypto_util
from acme import messages
from acme.magic_typing import List # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import Tuple # pylint: disable=unused-import, no-name-in-module
from acme.magic_typing import List
from acme.magic_typing import Tuple
from certbot import achallenges
from certbot import errors as le_errors
from certbot.tests import acme_util
Expand Down
Expand Up @@ -4,7 +4,7 @@

import requests
import six
from six.moves import xrange # pylint: disable=import-error, redefined-builtin
from six.moves import xrange

from acme import crypto_util
from acme import errors as acme_errors
Expand All @@ -13,7 +13,6 @@


class Validator(object):
# pylint: disable=no-self-use
"""Collection of functions to test a live webserver's configuration"""

def certificate(self, cert, name, alt_host=None, port=443):
Expand Down
Expand Up @@ -38,7 +38,7 @@ def add_parser_arguments(cls, add): # pylint: disable=arguments-differ
super(Authenticator, cls).add_parser_arguments(add)
add('credentials', help='Cloudflare credentials INI file.')

def more_info(self): # pylint: disable=missing-docstring,no-self-use
def more_info(self): # pylint: disable=missing-function-docstring
return 'This plugin configures a DNS TXT record to respond to a dns-01 challenge using ' + \
'the Cloudflare API.'

Expand Down
Expand Up @@ -34,7 +34,7 @@ def add_parser_arguments(cls, add): # pylint: disable=arguments-differ
super(Authenticator, cls).add_parser_arguments(add, default_propagation_seconds=30)
add('credentials', help='CloudXNS credentials INI file.')

def more_info(self): # pylint: disable=missing-docstring,no-self-use
def more_info(self): # pylint: disable=missing-function-docstring
return 'This plugin configures a DNS TXT record to respond to a dns-01 challenge using ' + \
'the CloudXNS API.'

Expand Down
Expand Up @@ -30,7 +30,7 @@ def add_parser_arguments(cls, add): # pylint: disable=arguments-differ
super(Authenticator, cls).add_parser_arguments(add)
add('credentials', help='DigitalOcean credentials INI file.')

def more_info(self): # pylint: disable=missing-docstring,no-self-use
def more_info(self): # pylint: disable=missing-function-docstring
return 'This plugin configures a DNS TXT record to respond to a dns-01 challenge using ' + \
'the DigitalOcean API.'

Expand Down

0 comments on commit fc7e5e8

Please sign in to comment.