From 56ab72d28c04fd6e702874033d0c3303d0cecc20 Mon Sep 17 00:00:00 2001 From: aoright <102943475+aoright@users.noreply.github.com> Date: Tue, 18 Aug 2026 17:10:33 +0800 Subject: [PATCH] fix(scripts): clean unused imports and tuple optimizations in check_readme.py Signed-off-by: aoright <102943475+aoright@users.noreply.github.com> --- scripts/check_readme.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) mode change 100644 => 100755 scripts/check_readme.py diff --git a/scripts/check_readme.py b/scripts/check_readme.py old mode 100644 new mode 100755 index b3011684d..d1a32cab6 --- a/scripts/check_readme.py +++ b/scripts/check_readme.py @@ -17,17 +17,17 @@ report --results F --state F """ import argparse -import json +from concurrent.futures import ThreadPoolExecutor, as_completed +from datetime import date +from html.parser import HTMLParser import http.client +import json import re import socket import ssl import sys import threading import time -from concurrent.futures import ThreadPoolExecutor, as_completed -from datetime import date, timezone -from html.parser import HTMLParser from urllib.parse import urljoin, urlsplit SCRIPT_DIR_NAME = "scripts" @@ -70,7 +70,7 @@ # -------------------------------------------------------------------------- class Diagnostic: - __slots__ = ("line", "code", "severity", "message") + __slots__ = ("code", "line", "message", "severity") def __init__(self, line, code, severity, message): self.line = line @@ -423,7 +423,7 @@ def parse_unified_diff(text): cur_new = None hunk_re = re.compile(r"^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@") for raw in text.split("\n"): - if raw.startswith("+++") or raw.startswith("---"): + if raw.startswith(("+++", "---")): continue m = hunk_re.match(raw) if m: @@ -457,7 +457,7 @@ def cmd_check_diff(args): if tag == "toc": continue if tag == "entry": - _, depth, title, url, tail, extra_urls = kind + _, _depth, title, url, _tail, extra_urls = kind if url.startswith("http://"): diags.append(Diagnostic(lineno, "E101", "error", f"new http:// link (use https:// if available): {url}")) if "youtu.be" in urlsplit(url).netloc.lower(): @@ -588,7 +588,7 @@ def _attempt_with_fallback(url, timeout): """One HEAD (with GET fallback on certain statuses). Returns (status, headers, body, exc).""" try: status, headers, body = _single_http_call(url, "HEAD", timeout) - except Exception as exc: + except Exception: try: status, headers, body = _single_http_call(url, "GET", timeout) except Exception as exc2: @@ -1101,8 +1101,13 @@ def cmd_prune(args): def render_prune_pr_body(removals, updates): - out = ["Automated fix from the weekly link-rot sweep -- only confirmed-dead " - "removals and moved-URL updates, nothing else is touched.", ""] + out = [ + ( + "Automated fix from the weekly link-rot sweep -- only confirmed-dead " + "removals and moved-URL updates, nothing else is touched." + ), + "", + ] if removals: out.append(f"### Removed ({len(removals)}) -- confirmed dead for 2+ consecutive weekly checks") out.append("")