Commit c1aff5c9 by Alp Arıbal Committed by GitHub

ci: use flake8-pie (#6164)

Relates-to: #4776 

Adding the hook leads to four new warnings for the repo.
-
[PIE803](https://github.com/sbdchd/flake8-pie#pie803-prefer-logging-interpolation):
prefer-logging-interpolation
This check produces false positives (`debug()` calls are always flagged
as if they belong to a logger). PR ignores such instances and fixes the
rest.
-
[PIE786](https://github.com/sbdchd/flake8-pie#pie786-precise-exception-handlers):
precise-exception-handlers
PR ignores instances where the intention is indeed to catch any
exceptions and fixes the rest.
-
[PIE798](https://github.com/sbdchd/flake8-pie#pie798-no-unnecessary-class):
no-unnecessary-class
All instances are ignored via an additional entry in flake8 config.
parent 6b924a21
......@@ -17,6 +17,10 @@ extend-ignore =
ANN101,
# ANN102: Missing type annotation for cls in classmethod
ANN102,
# PIE781: assign-and-return
PIE781,
# PIE798 no-unnecessary-class: Consider using a module for namespacing instead
PIE798,
per-file-ignores =
# TC002: Move third-party import '...' into a type-checking block
__init__.py:TC002,
......
......@@ -43,6 +43,7 @@ repos:
- flake8-typing-imports==1.12.0
- flake8-use-fstring==1.4
- pep8-naming==0.13.1
- flake8-pie==0.16.0
- repo: https://github.com/asottile/pyupgrade
rev: v2.37.3
......
......@@ -26,5 +26,5 @@ class IOHandler(logging.Handler):
self._io.write_error_line(msg)
else:
self._io.write_line(msg)
except Exception:
except Exception: # noqa: PIE786
self.handleError(record)
......@@ -206,8 +206,10 @@ class PackageInfo:
except ValueError:
# Likely unable to parse constraint so we skip it
logger.debug(
f"Invalid constraint ({req}) found in"
f" {package.name}-{package.version} dependencies, skipping",
"Invalid constraint (%s) found in %s-%s dependencies, skipping",
req,
package.name,
package.version,
)
continue
......
......@@ -264,7 +264,7 @@ class Executor:
# error to be picked up by the error handler.
if result == -2:
raise KeyboardInterrupt
except Exception as e:
except Exception as e: # noqa: PIE786
try:
from cleo.ui.exception_trace import ExceptionTrace
......
......@@ -71,7 +71,7 @@ class PluginManager:
plugin.activate(*args, **kwargs)
def _load_plugin_entry_point(self, ep: metadata.EntryPoint) -> None:
logger.debug(f"Loading the {ep.name} plugin") # type: ignore[attr-defined]
logger.debug("Loading the %s plugin", ep.name) # type: ignore[attr-defined]
plugin = ep.load() # type: ignore[no-untyped-call]
......
......@@ -57,14 +57,14 @@ class Publisher:
# Check if we have a token first
token = self._authenticator.get_pypi_token(repository_name)
if token:
logger.debug(f"Found an API token for {repository_name}.")
logger.debug("Found an API token for %s.", repository_name)
username = "__token__"
password = token
else:
auth = self._authenticator.get_http_auth(repository_name)
if auth:
logger.debug(
f"Found authentication information for {repository_name}."
"Found authentication information for %s.", repository_name
)
username = auth.username
password = auth.password
......
......@@ -76,11 +76,13 @@ class Solver:
if len(self._overrides) > 1:
self._provider.debug(
f"Complete version solving took {end - start:.3f} seconds with"
f" {len(self._overrides)} overrides"
# ignore the warning as provider does not do interpolation
f"Complete version solving took {end - start:.3f}" # noqa: PIE803
f" seconds with {len(self._overrides)} overrides"
)
self._provider.debug(
"Resolved with overrides:"
# ignore the warning as provider does not do interpolation
"Resolved with overrides:" # noqa: PIE803
f" {', '.join(f'({b})' for b in self._overrides)}"
)
......@@ -125,7 +127,8 @@ class Solver:
depths = []
for override in overrides:
self._provider.debug(
"<comment>Retrying dependency resolution "
# ignore the warning as provider does not do interpolation
"<comment>Retrying dependency resolution " # noqa: PIE803
f"with the following overrides ({override}).</comment>"
)
self._provider.set_overrides(override)
......
......@@ -258,7 +258,7 @@ class Authenticator:
if not is_last_attempt:
attempt += 1
delay = 0.5 * attempt
logger.debug(f"Retrying HTTP request in {delay} seconds.")
logger.debug("Retrying HTTP request in %s seconds.", delay)
time.sleep(delay)
continue
......
......@@ -109,8 +109,8 @@ class PoetryKeyring:
def _check(self) -> None:
try:
import keyring
except Exception as e:
logger.debug(f"An error occurred while importing keyring: {e!s}")
except ImportError as e:
logger.debug("An error occurred while importing keyring: %s", e)
self._is_available = False
return
......@@ -134,7 +134,7 @@ class PoetryKeyring:
and "plaintext" not in b.name.lower()
for b in backends
)
except Exception:
except ImportError:
self._is_available = False
if not self._is_available:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment