From 7e5e51aeff46d5cda0ee92f64b9ba4b5058f5dd7 Mon Sep 17 00:00:00 2001 From: Mads Jensen Date: Sun, 9 Jan 2022 22:50:44 +0100 Subject: [PATCH 1/2] Use super().__init__ instead of explicitly calling named super-class. (#9166) * Use super().__init__ instead of explicitly calling named super-class. * Fix unittest (typo fix). --- acme/acme/standalone.py | 15 +++++++-------- acme/tests/standalone_test.py | 4 +--- .../certbot_nginx/_internal/nginxparser.py | 2 +- certbot/certbot/_internal/error_handler.py | 3 ++- certbot/tests/plugins/dns_common_test.py | 2 +- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/acme/acme/standalone.py b/acme/acme/standalone.py index cd2caa221..5dfb27136 100644 --- a/acme/acme/standalone.py +++ b/acme/acme/standalone.py @@ -34,10 +34,9 @@ class TLSServer(socketserver.TCPServer): else: self.address_family = socket.AF_INET self.certs = kwargs.pop("certs", {}) - self.method = kwargs.pop( - "method", crypto_util._DEFAULT_SSL_METHOD) + self.method = kwargs.pop("method", crypto_util._DEFAULT_SSL_METHOD) self.allow_reuse_address = kwargs.pop("allow_reuse_address", True) - socketserver.TCPServer.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) def _wrap_sock(self) -> None: self.socket = crypto_util.SSLSocket( @@ -190,7 +189,7 @@ class HTTPServer(BaseHTTPServer.HTTPServer): self.address_family = socket.AF_INET6 else: self.address_family = socket.AF_INET - BaseHTTPServer.HTTPServer.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) class HTTP01Server(HTTPServer, ACMEServerMixin): @@ -198,8 +197,8 @@ class HTTP01Server(HTTPServer, ACMEServerMixin): def __init__(self, server_address: Tuple[str, int], resources: Set[challenges.HTTP01], ipv6: bool = False, timeout: int = 30) -> None: - HTTPServer.__init__( - self, server_address, HTTP01RequestHandler.partial_init( + super().__init__( + server_address, HTTP01RequestHandler.partial_init( simple_http_resources=resources, timeout=timeout), ipv6=ipv6) @@ -208,7 +207,7 @@ class HTTP01DualNetworkedServers(BaseDualNetworkedServers): affect the other.""" def __init__(self, *args: Any, **kwargs: Any) -> None: - BaseDualNetworkedServers.__init__(self, HTTP01Server, *args, **kwargs) + super().__init__(HTTP01Server, *args, **kwargs) class HTTP01RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): @@ -226,7 +225,7 @@ class HTTP01RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): def __init__(self, *args: Any, **kwargs: Any) -> None: self.simple_http_resources = kwargs.pop("simple_http_resources", set()) self._timeout = kwargs.pop('timeout', 30) - BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) self.server: HTTP01Server # In parent class BaseHTTPRequestHandler, 'timeout' is a class-level property but we diff --git a/acme/tests/standalone_test.py b/acme/tests/standalone_test.py index e0aa5aa22..ad5751fcf 100644 --- a/acme/tests/standalone_test.py +++ b/acme/tests/standalone_test.py @@ -165,7 +165,6 @@ class TLSALPN01ServerTest(unittest.TestCase): class BaseDualNetworkedServersTest(unittest.TestCase): """Test for acme.standalone.BaseDualNetworkedServers.""" - class SingleProtocolServer(socketserver.TCPServer): """Server that only serves on a single protocol. FreeBSD has this behavior for AF_INET6.""" def __init__(self, *args, **kwargs): @@ -175,7 +174,7 @@ class BaseDualNetworkedServersTest(unittest.TestCase): kwargs["bind_and_activate"] = False else: self.address_family = socket.AF_INET - socketserver.TCPServer.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) if ipv6: # NB: On Windows, socket.IPPROTO_IPV6 constant may be missing. # We use the corresponding value (41) instead. @@ -202,7 +201,6 @@ class BaseDualNetworkedServersTest(unittest.TestCase): self.assertEqual(em.exception.errno, EADDRINUSE) - def test_ports_equal(self): from acme.standalone import BaseDualNetworkedServers servers = BaseDualNetworkedServers( diff --git a/certbot-nginx/certbot_nginx/_internal/nginxparser.py b/certbot-nginx/certbot_nginx/_internal/nginxparser.py index 2aa677c38..03aa88db4 100644 --- a/certbot-nginx/certbot_nginx/_internal/nginxparser.py +++ b/certbot-nginx/certbot_nginx/_internal/nginxparser.py @@ -118,7 +118,7 @@ class UnspacedList(list): # Turn self into a version of the source list that has spaces removed # and all sub-lists also UnspacedList()ed - list.__init__(self, list_source) + super().__init__(list_source) for i, entry in reversed(list(enumerate(self))): if isinstance(entry, list): sublist = UnspacedList(entry) diff --git a/certbot/certbot/_internal/error_handler.py b/certbot/certbot/_internal/error_handler.py index 0e63d02de..24ab46d9d 100644 --- a/certbot/certbot/_internal/error_handler.py +++ b/certbot/certbot/_internal/error_handler.py @@ -167,6 +167,7 @@ class ErrorHandler: logger.debug("Calling signal %s", signum) os.kill(os.getpid(), signum) + class ExitHandler(ErrorHandler): """Context manager for running code that must be cleaned up. @@ -175,5 +176,5 @@ class ExitHandler(ErrorHandler): regular exit. """ def __init__(self, func: Callable[..., Any], *args: Any, **kwargs: Any) -> None: - ErrorHandler.__init__(self, func, *args, **kwargs) + super().__init__(func, *args, **kwargs) self.call_on_regular_exit = True diff --git a/certbot/tests/plugins/dns_common_test.py b/certbot/tests/plugins/dns_common_test.py index 41117f894..f68d36137 100644 --- a/certbot/tests/plugins/dns_common_test.py +++ b/certbot/tests/plugins/dns_common_test.py @@ -133,7 +133,7 @@ class CredentialsConfigurationTest(test_util.TempDirTestCase): def __init__(self, *args, **kwargs): self.reset() - logging.Handler.__init__(self, *args, **kwargs) + super().__init__(*args, **kwargs) def emit(self, record): self.messages[record.levelname.lower()].append(record.getMessage()) From 30b066f08260b73fc26256b5484a180468b9d0a6 Mon Sep 17 00:00:00 2001 From: Mads Jensen Date: Sun, 9 Jan 2022 22:51:06 +0100 Subject: [PATCH 2/2] Remove outdated pylint comments (#9167) * Remove outdated pylint: disable=unused-import annotations. * remove # pylint: disable=ungrouped-imports annotations. * Remove single pylint: disable = unused-argument in DeleteIfAppropriateTest.test_opt_in_deletion. --- certbot-apache/certbot_apache/_internal/http_01.py | 2 +- certbot-nginx/certbot_nginx/_internal/configurator.py | 2 +- certbot/certbot/_internal/account.py | 4 +++- certbot/certbot/ocsp.py | 2 +- certbot/tests/display/completer_test.py | 6 +++--- certbot/tests/main_test.py | 3 +-- certbot/tests/plugins/standalone_test.py | 5 ++--- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/certbot-apache/certbot_apache/_internal/http_01.py b/certbot-apache/certbot_apache/_internal/http_01.py index 749a57634..117eec2a5 100644 --- a/certbot-apache/certbot_apache/_internal/http_01.py +++ b/certbot-apache/certbot_apache/_internal/http_01.py @@ -9,7 +9,7 @@ from certbot import errors from certbot.compat import filesystem from certbot.compat import os from certbot.plugins import common -from certbot_apache._internal.obj import VirtualHost # pylint: disable=unused-import +from certbot_apache._internal.obj import VirtualHost from certbot_apache._internal.parser import get_aug_path if TYPE_CHECKING: diff --git a/certbot-nginx/certbot_nginx/_internal/configurator.py b/certbot-nginx/certbot_nginx/_internal/configurator.py index ede184159..46ec7d57e 100644 --- a/certbot-nginx/certbot_nginx/_internal/configurator.py +++ b/certbot-nginx/certbot_nginx/_internal/configurator.py @@ -28,7 +28,7 @@ from certbot_nginx._internal import constants from certbot_nginx._internal import display_ops from certbot_nginx._internal import http_01 from certbot_nginx._internal import nginxparser -from certbot_nginx._internal import obj # pylint: disable=unused-import +from certbot_nginx._internal import obj from certbot_nginx._internal import parser NAME_RANK = 0 diff --git a/certbot/certbot/_internal/account.py b/certbot/certbot/_internal/account.py index 07a869789..041fe9cf5 100644 --- a/certbot/certbot/_internal/account.py +++ b/certbot/certbot/_internal/account.py @@ -20,7 +20,7 @@ import pytz from acme import fields as acme_fields from acme import messages -from acme.client import ClientBase # pylint: disable=unused-import +from acme.client import ClientBase from certbot import configuration from certbot import errors from certbot import interfaces @@ -125,6 +125,7 @@ class AccountMemoryStorage(interfaces.AccountStorage): except KeyError: raise errors.AccountNotFound(account_id) + class RegistrationResourceWithNewAuthzrURI(messages.RegistrationResource): """A backwards-compatible RegistrationResource with a new-authz URI. @@ -136,6 +137,7 @@ class RegistrationResourceWithNewAuthzrURI(messages.RegistrationResource): """ new_authzr_uri = jose.Field('new_authzr_uri') + class AccountFileStorage(interfaces.AccountStorage): """Accounts file storage. diff --git a/certbot/certbot/ocsp.py b/certbot/certbot/ocsp.py index 51d486b6b..2a51fe834 100644 --- a/certbot/certbot/ocsp.py +++ b/certbot/certbot/ocsp.py @@ -22,7 +22,7 @@ from certbot import crypto_util from certbot import errors from certbot import util from certbot.compat.os import getenv -from certbot.interfaces import RenewableCert # pylint: disable=unused-import +from certbot.interfaces import RenewableCert logger = logging.getLogger(__name__) diff --git a/certbot/tests/display/completer_test.py b/certbot/tests/display/completer_test.py index 75b11d1d7..a6ada8b9a 100644 --- a/certbot/tests/display/completer_test.py +++ b/certbot/tests/display/completer_test.py @@ -10,9 +10,9 @@ import string import sys import unittest -from certbot.compat import filesystem # pylint: disable=ungrouped-imports -from certbot.compat import os # pylint: disable=ungrouped-imports -import certbot.tests.util as test_util # pylint: disable=ungrouped-imports +from certbot.compat import filesystem +from certbot.compat import os +import certbot.tests.util as test_util try: import mock diff --git a/certbot/tests/main_test.py b/certbot/tests/main_test.py index 9a67f0853..18c8b8081 100644 --- a/certbot/tests/main_test.py +++ b/certbot/tests/main_test.py @@ -18,7 +18,7 @@ import pytz from certbot import crypto_util, configuration from certbot import errors -from certbot import interfaces # pylint: disable=unused-import +from certbot import interfaces from certbot import util from certbot._internal import account from certbot._internal import cli @@ -529,7 +529,6 @@ class DeleteIfAppropriateTest(test_util.ConfigTestCase): def test_opt_in_deletion(self, mock_get_utility, mock_delete, mock_cert_path_to_lineage, mock_full_archive_dir, mock_match_and_check_overlaps, mock_renewal_file_for_certname): - # pylint: disable = unused-argument config = self.config config.namespace.delete_after_revoke = True config.cert_path = "/some/reasonable/path" diff --git a/certbot/tests/plugins/standalone_test.py b/certbot/tests/plugins/standalone_test.py index 3c990a3f5..2649abae9 100644 --- a/certbot/tests/plugins/standalone_test.py +++ b/certbot/tests/plugins/standalone_test.py @@ -7,10 +7,10 @@ from typing import Tuple import unittest import josepy as jose -import OpenSSL.crypto # pylint: disable=unused-import +import OpenSSL.crypto from acme import challenges -from acme import standalone as acme_standalone # pylint: disable=unused-import +from acme import standalone as acme_standalone from certbot import achallenges from certbot import errors from certbot.tests import acme_util @@ -22,7 +22,6 @@ except ImportError: # pragma: no cover from unittest import mock - class ServerManagerTest(unittest.TestCase): """Tests for certbot._internal.plugins.standalone.ServerManager."""