diff --git a/.flake8 b/.flake8 index c2389cff812..2d16cf2abc3 100644 --- a/.flake8 +++ b/.flake8 @@ -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, diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index eeac4684d91..851b27751a9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/src/poetry/console/logging/io_handler.py b/src/poetry/console/logging/io_handler.py index 213a87a3658..e759ca46af3 100644 --- a/src/poetry/console/logging/io_handler.py +++ b/src/poetry/console/logging/io_handler.py @@ -26,5 +26,5 @@ def emit(self, record: LogRecord) -> None: self._io.write_error_line(msg) else: self._io.write_line(msg) - except Exception: + except Exception: # noqa: PIE786 self.handleError(record) diff --git a/src/poetry/inspection/info.py b/src/poetry/inspection/info.py index 7e851223b5a..d4b91ae3d19 100644 --- a/src/poetry/inspection/info.py +++ b/src/poetry/inspection/info.py @@ -201,8 +201,10 @@ def to_package( 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 diff --git a/src/poetry/installation/executor.py b/src/poetry/installation/executor.py index c582b0d9ea7..1bde4573696 100644 --- a/src/poetry/installation/executor.py +++ b/src/poetry/installation/executor.py @@ -254,7 +254,7 @@ def _execute_operation(self, operation: Operation) -> None: # 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 diff --git a/src/poetry/plugins/plugin_manager.py b/src/poetry/plugins/plugin_manager.py index 99d83ee91c5..1a01dc36335 100644 --- a/src/poetry/plugins/plugin_manager.py +++ b/src/poetry/plugins/plugin_manager.py @@ -71,7 +71,7 @@ def activate(self, *args: Any, **kwargs: Any) -> None: 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] diff --git a/src/poetry/publishing/publisher.py b/src/poetry/publishing/publisher.py index cf8515bcf46..a5335258041 100644 --- a/src/poetry/publishing/publisher.py +++ b/src/poetry/publishing/publisher.py @@ -57,14 +57,14 @@ def publish( # 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 diff --git a/src/poetry/puzzle/solver.py b/src/poetry/puzzle/solver.py index 815e5d54766..d519e530004 100644 --- a/src/poetry/puzzle/solver.py +++ b/src/poetry/puzzle/solver.py @@ -75,11 +75,13 @@ def solve(self, use_latest: list[str] | None = None) -> Transaction: 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)}" ) @@ -99,7 +101,8 @@ def solve_in_compatibility_mode( depths = [] for override in overrides: self._provider.debug( - "Retrying dependency resolution " + # ignore the warning as provider does not do interpolation + "Retrying dependency resolution " # noqa: PIE803 f"with the following overrides ({override})." ) self._provider.set_overrides(override) diff --git a/src/poetry/utils/authenticator.py b/src/poetry/utils/authenticator.py index fbcb25ea502..f13e46673c8 100644 --- a/src/poetry/utils/authenticator.py +++ b/src/poetry/utils/authenticator.py @@ -243,7 +243,7 @@ def request( 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 diff --git a/src/poetry/utils/password_manager.py b/src/poetry/utils/password_manager.py index 78a5559b2ae..dfb72870375 100644 --- a/src/poetry/utils/password_manager.py +++ b/src/poetry/utils/password_manager.py @@ -109,8 +109,8 @@ def get_entry_name(self, name: str) -> str: 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 @@ def _check(self) -> None: and "plaintext" not in b.name.lower() for b in backends ) - except Exception: + except ImportError: self._is_available = False if not self._is_available: