From 2cc4ff200a8f221190660f802c04e7de56945b97 Mon Sep 17 00:00:00 2001 From: Adrien Ferrand Date: Wed, 27 Oct 2021 00:19:32 +0200 Subject: [PATCH] Fix lint --- .pylintrc | 4 +++- acme/acme/challenges.py | 2 +- acme/acme/client.py | 6 +++--- acme/acme/messages.py | 11 ++++++----- certbot-apache/certbot_apache/_internal/entrypoint.py | 2 +- certbot/certbot/_internal/client.py | 2 +- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.pylintrc b/.pylintrc index ccd660239..d2730018d 100644 --- a/.pylintrc +++ b/.pylintrc @@ -72,7 +72,9 @@ extension-pkg-whitelist=pywintypes,win32api,win32file,win32security # (unspecified encoding makes the open function use the default encoding of the system) # than a clear flaw on which a check should be enforced. Anyway the project does # not need to enforce encoding on files so we disable this check. -disable=fixme,locally-disabled,locally-enabled,bad-continuation,no-self-use,invalid-name,cyclic-import,duplicate-code,design,import-outside-toplevel,useless-object-inheritance,unsubscriptable-object,no-value-for-parameter,no-else-return,no-else-raise,no-else-break,no-else-continue,raise-missing-from,wrong-import-order,unspecified-encoding +# 7) consider-using-f-string is "suggesting" to move to f-string when possible with an error. This +# clearly relates to code design and not to potential defects in the code, let's just ignore that. +disable=fixme,locally-disabled,locally-enabled,bad-continuation,no-self-use,invalid-name,cyclic-import,duplicate-code,design,import-outside-toplevel,useless-object-inheritance,unsubscriptable-object,no-value-for-parameter,no-else-return,no-else-raise,no-else-break,no-else-continue,raise-missing-from,wrong-import-order,unspecified-encoding,consider-using-f-string [REPORTS] diff --git a/acme/acme/challenges.py b/acme/acme/challenges.py index e20118987..884c76789 100644 --- a/acme/acme/challenges.py +++ b/acme/acme/challenges.py @@ -127,7 +127,7 @@ class KeyAuthorizationChallengeResponse(ChallengeResponse): :rtype: bool """ - parts = self.key_authorization.split('.') + parts = self.key_authorization.split('.') # pylint: disable=no-member if len(parts) != 2: logger.debug("Key authorization (%r) is not well formed", self.key_authorization) diff --git a/acme/acme/client.py b/acme/acme/client.py index f74719211..397f30b5f 100644 --- a/acme/acme/client.py +++ b/acme/acme/client.py @@ -158,7 +158,7 @@ class ClientBase: authzr = messages.AuthorizationResource( body=messages.Authorization.from_json(response.json()), uri=response.headers.get('Location', uri)) - if identifier is not None and authzr.body.identifier != identifier: + if identifier is not None and authzr.body.identifier != identifier: # pylint: disable=no-member raise errors.UnexpectedUpdate(authzr) return authzr @@ -495,7 +495,7 @@ class Client(ClientBase): updated[authzr] = updated_authzr attempts[authzr] += 1 - if updated_authzr.body.status not in ( + if updated_authzr.body.status not in ( # pylint: disable=no-member messages.STATUS_VALID, messages.STATUS_INVALID): if attempts[authzr] < max_attempts: # push back to the priority queue, with updated retry_after @@ -759,7 +759,7 @@ class ClientV2(ClientBase): for url in orderr.body.authorizations: while datetime.datetime.now() < deadline: authzr = self._authzr_from_response(self._post_as_get(url), uri=url) - if authzr.body.status != messages.STATUS_PENDING: + if authzr.body.status != messages.STATUS_PENDING: # pylint: disable=no-member responses.append(authzr) break time.sleep(1) diff --git a/acme/acme/messages.py b/acme/acme/messages.py index f29ecc057..b55340780 100644 --- a/acme/acme/messages.py +++ b/acme/acme/messages.py @@ -304,7 +304,7 @@ class ExternalAccountBinding: """Create External Account Binding Resource from contact details, kid and hmac.""" key_json = json.dumps(account_public_key.to_partial_json()).encode() - # Fix type with TO_DEFINE + # TODO: Remove type ignore when jose.b64.b64decode type hint is fixed (accepts str/bytes). decoded_hmac_key = jose.b64.b64decode(hmac_key) # type: ignore url = directory["newAccount"] @@ -335,7 +335,8 @@ class Registration(ResourceBody): status: Status = jose.field('status', omitempty=True) terms_of_service_agreed: bool = jose.field('termsOfServiceAgreed', omitempty=True) only_return_existing: bool = jose.field('onlyReturnExisting', omitempty=True) - external_account_binding: ExternalAccountBinding = jose.field('externalAccountBinding', omitempty=True) + external_account_binding: ExternalAccountBinding = jose.field('externalAccountBinding', + omitempty=True) phone_prefix = 'tel:' email_prefix = 'mailto:' @@ -527,7 +528,7 @@ class ChallengeResource(Resource): @property def uri(self) -> str: """The URL of the challenge body.""" - return self.body.uri + return self.body.uri # pylint: disable=no-member class Authorization(ResourceBody): @@ -556,7 +557,7 @@ class Authorization(ResourceBody): # Mypy does not understand the josepy magic happening here, and falsely claims # that challenge is redefined. Let's ignore the type check here. @challenges.decoder # type: ignore - def challenges(value: List[Mapping[str, Any]]) -> Tuple[ChallengeBody, ...]: # type: ignore[misc] # pylint: disable=no-self-argument,missing-function-docstring + def challenges(value: List[Dict[str, Any]]) -> Tuple[ChallengeBody, ...]: # type: ignore[misc] # pylint: disable=no-self-argument,missing-function-docstring return tuple(cast(ChallengeBody, ChallengeBody.from_json(chall)) for chall in value) @property @@ -656,7 +657,7 @@ class Order(ResourceBody): # Mypy does not understand the josepy magic happening here, and falsely claims # that identifiers is redefined. Let's ignore the type check here. @identifiers.decoder # type: ignore - def identifiers(value: List[Mapping[str, Any]]) -> Tuple[Identifier, ...]: # type: ignore[misc] # pylint: disable=no-self-argument,missing-function-docstring + def identifiers(value: List[Dict[str, Any]]) -> Tuple[Identifier, ...]: # type: ignore[misc] # pylint: disable=no-self-argument,missing-function-docstring return tuple(cast(Identifier, Identifier.from_json(identifier)) for identifier in value) diff --git a/certbot-apache/certbot_apache/_internal/entrypoint.py b/certbot-apache/certbot_apache/_internal/entrypoint.py index 96bef030c..e9a02feab 100644 --- a/certbot-apache/certbot_apache/_internal/entrypoint.py +++ b/certbot-apache/certbot_apache/_internal/entrypoint.py @@ -57,7 +57,7 @@ def get_configurator(): os_like = util.get_systemd_os_like() if os_like: for os_name in os_like: - if os_name in OVERRIDE_CLASSES.keys(): + if os_name in OVERRIDE_CLASSES: # pylint: disable=consider-using-get override_class = OVERRIDE_CLASSES[os_name] if not override_class: # No override class found, return the generic configurator diff --git a/certbot/certbot/_internal/client.py b/certbot/certbot/_internal/client.py index 899b051bf..d5065be3a 100644 --- a/certbot/certbot/_internal/client.py +++ b/certbot/certbot/_internal/client.py @@ -228,7 +228,7 @@ def perform_registration(acme, config, tos_cb): external_account_binding=eab) return acme.new_account_and_tos(newreg, tos_cb) except messages.Error as e: - if e.code == "invalidEmail" or e.code == "invalidContact": + if e.code in ("invalidEmail", "invalidContact"): if config.noninteractive_mode: msg = ("The ACME server believes %s is an invalid email address. " "Please ensure it is a valid email and attempt "