From 6a519db40f91e6d4bb56546e7c97ab4c92d43260 Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Sun, 30 Nov 2025 15:03:50 +0100 Subject: [PATCH] Enable TRY401: remove redundant exception object from logging.exception --- PYTHON/downloadCats/generate_cats.py | 4 ++-- PYTHON/lichess_bot/lichess_api.py | 4 ++-- PYTHON/lichess_bot/main.py | 4 ++-- PYTHON/lichess_bot/tools/generate_blunder_tests.py | 8 ++++---- PYTHON/randomize_numbers/random_digits.py | 4 ++-- pyproject.toml | 1 - 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/PYTHON/downloadCats/generate_cats.py b/PYTHON/downloadCats/generate_cats.py index 8f5b9d8..adfc8b4 100644 --- a/PYTHON/downloadCats/generate_cats.py +++ b/PYTHON/downloadCats/generate_cats.py @@ -40,5 +40,5 @@ while requests_send < MAX_REQUESTS: logging.info(f"Saved {url} as {image_path}") - except requests.exceptions.RequestException as e: - logging.exception(f"Failed to download {url}: {e}") + except requests.exceptions.RequestException: + logging.exception(f"Failed to download {url}") diff --git a/PYTHON/lichess_bot/lichess_api.py b/PYTHON/lichess_bot/lichess_api.py index 3c4859e..d7ad36c 100644 --- a/PYTHON/lichess_bot/lichess_api.py +++ b/PYTHON/lichess_bot/lichess_api.py @@ -41,8 +41,8 @@ class LichessAPI: logging.info(f"HTTP {method} {url} -> sending") try: r = self.session.request(method, url, **kwargs) - except Exception as e: - logging.exception(f"HTTP {method} {url} -> exception: {e}") + except Exception: + logging.exception(f"HTTP {method} {url} -> exception") raise elapsed = time.monotonic() - t0 status = r.status_code diff --git a/PYTHON/lichess_bot/main.py b/PYTHON/lichess_bot/main.py index 1efb900..1c3f13b 100644 --- a/PYTHON/lichess_bot/main.py +++ b/PYTHON/lichess_bot/main.py @@ -235,8 +235,8 @@ def run_bot(log_level: str = "INFO", decline_correspondence: bool = False) -> No break elif et in {"chatLine", "opponentGone"}: continue - except Exception as e: - logging.exception(f"Game {game_id} thread error: {e}") + except Exception: + logging.exception(f"Game {game_id} thread error") finally: # On game end, write full PGN to the log file try: diff --git a/PYTHON/lichess_bot/tools/generate_blunder_tests.py b/PYTHON/lichess_bot/tools/generate_blunder_tests.py index 94c4b9a..1014679 100755 --- a/PYTHON/lichess_bot/tools/generate_blunder_tests.py +++ b/PYTHON/lichess_bot/tools/generate_blunder_tests.py @@ -335,8 +335,8 @@ def _process_single_log(log_path: str) -> int: try: blunders = parse_columns_for_blunders(text) - except Exception as e: - logging.exception(f"Error parsing Columns in {os.path.basename(log_path)}: {e}") + except Exception: + logging.exception(f"Error parsing Columns in {os.path.basename(log_path)}") return 2 if not blunders: logging.warning( @@ -351,9 +351,9 @@ def _process_single_log(log_path: str) -> int: try: cases = fen_and_uci_for_blunders(pgn_text, blunders) - except Exception as e: + except Exception: logging.exception( - f"Error converting SAN to UCI in {os.path.basename(log_path)}: {e}" + f"Error converting SAN to UCI in {os.path.basename(log_path)}" ) return 2 if not cases: diff --git a/PYTHON/randomize_numbers/random_digits.py b/PYTHON/randomize_numbers/random_digits.py index cc47949..13266c5 100644 --- a/PYTHON/randomize_numbers/random_digits.py +++ b/PYTHON/randomize_numbers/random_digits.py @@ -85,7 +85,7 @@ if __name__ == "__main__": logging.info(f"Original numbers: {numbers}") logging.info(f"Randomized numbers: {formatted_numbers}") - except ValueError as e: - logging.exception(f"Error: {e}") + except ValueError: + logging.exception("Error processing numbers") logging.exception("Please provide valid numbers and percentages.") sys.exit(1) diff --git a/pyproject.toml b/pyproject.toml index f420d20..81749f9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,7 +58,6 @@ ignore = [ "FBT003", # Boolean positional value - common pattern "ARG001", # Unused function argument - often needed for API compatibility "ARG002", # Unused method argument - often needed for API compatibility - "TRY401", # Verbose log message - acceptable "PERF203", # try-except-in-loop - often necessary "PGH003", # blanket-type-ignore - existing code "PLC0415", # import-outside-top-level - sometimes necessary