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 = ...@@ -17,6 +17,10 @@ extend-ignore =
ANN101, ANN101,
# ANN102: Missing type annotation for cls in classmethod # ANN102: Missing type annotation for cls in classmethod
ANN102, ANN102,
# PIE781: assign-and-return
PIE781,
# PIE798 no-unnecessary-class: Consider using a module for namespacing instead
PIE798,
per-file-ignores = per-file-ignores =
# TC002: Move third-party import '...' into a type-checking block # TC002: Move third-party import '...' into a type-checking block
__init__.py:TC002, __init__.py:TC002,
......
...@@ -43,6 +43,7 @@ repos: ...@@ -43,6 +43,7 @@ repos:
- flake8-typing-imports==1.12.0 - flake8-typing-imports==1.12.0
- flake8-use-fstring==1.4 - flake8-use-fstring==1.4
- pep8-naming==0.13.1 - pep8-naming==0.13.1
- flake8-pie==0.16.0
- repo: https://github.com/asottile/pyupgrade - repo: https://github.com/asottile/pyupgrade
rev: v2.37.3 rev: v2.37.3
......
...@@ -26,5 +26,5 @@ class IOHandler(logging.Handler): ...@@ -26,5 +26,5 @@ class IOHandler(logging.Handler):
self._io.write_error_line(msg) self._io.write_error_line(msg)
else: else:
self._io.write_line(msg) self._io.write_line(msg)
except Exception: except Exception: # noqa: PIE786
self.handleError(record) self.handleError(record)
...@@ -206,8 +206,10 @@ class PackageInfo: ...@@ -206,8 +206,10 @@ class PackageInfo:
except ValueError: except ValueError:
# Likely unable to parse constraint so we skip it # Likely unable to parse constraint so we skip it
logger.debug( logger.debug(
f"Invalid constraint ({req}) found in" "Invalid constraint (%s) found in %s-%s dependencies, skipping",
f" {package.name}-{package.version} dependencies, skipping", req,
package.name,
package.version,
) )
continue continue
......
...@@ -264,7 +264,7 @@ class Executor: ...@@ -264,7 +264,7 @@ class Executor:
# error to be picked up by the error handler. # error to be picked up by the error handler.
if result == -2: if result == -2:
raise KeyboardInterrupt raise KeyboardInterrupt
except Exception as e: except Exception as e: # noqa: PIE786
try: try:
from cleo.ui.exception_trace import ExceptionTrace from cleo.ui.exception_trace import ExceptionTrace
......
...@@ -71,7 +71,7 @@ class PluginManager: ...@@ -71,7 +71,7 @@ class PluginManager:
plugin.activate(*args, **kwargs) plugin.activate(*args, **kwargs)
def _load_plugin_entry_point(self, ep: metadata.EntryPoint) -> None: 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] plugin = ep.load() # type: ignore[no-untyped-call]
......
...@@ -57,14 +57,14 @@ class Publisher: ...@@ -57,14 +57,14 @@ class Publisher:
# Check if we have a token first # Check if we have a token first
token = self._authenticator.get_pypi_token(repository_name) token = self._authenticator.get_pypi_token(repository_name)
if token: if token:
logger.debug(f"Found an API token for {repository_name}.") logger.debug("Found an API token for %s.", repository_name)
username = "__token__" username = "__token__"
password = token password = token
else: else:
auth = self._authenticator.get_http_auth(repository_name) auth = self._authenticator.get_http_auth(repository_name)
if auth: if auth:
logger.debug( logger.debug(
f"Found authentication information for {repository_name}." "Found authentication information for %s.", repository_name
) )
username = auth.username username = auth.username
password = auth.password password = auth.password
......
...@@ -76,11 +76,13 @@ class Solver: ...@@ -76,11 +76,13 @@ class Solver:
if len(self._overrides) > 1: if len(self._overrides) > 1:
self._provider.debug( self._provider.debug(
f"Complete version solving took {end - start:.3f} seconds with" # ignore the warning as provider does not do interpolation
f" {len(self._overrides)} overrides" f"Complete version solving took {end - start:.3f}" # noqa: PIE803
f" seconds with {len(self._overrides)} overrides"
) )
self._provider.debug( 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)}" f" {', '.join(f'({b})' for b in self._overrides)}"
) )
...@@ -125,7 +127,8 @@ class Solver: ...@@ -125,7 +127,8 @@ class Solver:
depths = [] depths = []
for override in overrides: for override in overrides:
self._provider.debug( 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>" f"with the following overrides ({override}).</comment>"
) )
self._provider.set_overrides(override) self._provider.set_overrides(override)
......
...@@ -258,7 +258,7 @@ class Authenticator: ...@@ -258,7 +258,7 @@ class Authenticator:
if not is_last_attempt: if not is_last_attempt:
attempt += 1 attempt += 1
delay = 0.5 * attempt 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) time.sleep(delay)
continue continue
......
...@@ -109,8 +109,8 @@ class PoetryKeyring: ...@@ -109,8 +109,8 @@ class PoetryKeyring:
def _check(self) -> None: def _check(self) -> None:
try: try:
import keyring import keyring
except Exception as e: except ImportError as e:
logger.debug(f"An error occurred while importing keyring: {e!s}") logger.debug("An error occurred while importing keyring: %s", e)
self._is_available = False self._is_available = False
return return
...@@ -134,7 +134,7 @@ class PoetryKeyring: ...@@ -134,7 +134,7 @@ class PoetryKeyring:
and "plaintext" not in b.name.lower() and "plaintext" not in b.name.lower()
for b in backends for b in backends
) )
except Exception: except ImportError:
self._is_available = False self._is_available = False
if not self._is_available: 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