fix: 全站 ruff 清零 — 77 errors → 0
Fixes: - F821: install.py site_url 未定义(NameError)、sync_v2.py os 未导入、script_jobs.py LOG f-string - F401: 移除 22 个未使用导入(models/__init__.py、install.py、auth.py 等) - B904: 20 个 except 块 raise 添加 from e/from None - S110: 20 个有意的 try-except-pass 添加 noqa 注释(SSH清理/DDL幂等/WS断连) - B007: 3 个未使用循环变量重命名(dirs→_dirs、server_id→_server_id) - F541: 3 个无占位符 f-string 修正 - F841: auth.py 未使用 ip_address 变量移除 - S105: auth_service.py Redis key prefix 误报 noqa - B023: script_execution_flush.py 循环变量绑定修复 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -74,10 +74,10 @@ class AsyncSSHPool:
|
||||
pass
|
||||
|
||||
async with self._lock:
|
||||
for server_id, pooled in self._pool.items():
|
||||
for _server_id, pooled in self._pool.items():
|
||||
try:
|
||||
pooled.conn.close()
|
||||
except Exception:
|
||||
except Exception: # noqa: S110 — best-effort cleanup
|
||||
pass
|
||||
self._pool.clear()
|
||||
logger.info("AsyncSSH pool stopped — all connections closed")
|
||||
@@ -118,7 +118,7 @@ class AsyncSSHPool:
|
||||
# Close our new connection, reuse the existing one
|
||||
try:
|
||||
conn.close()
|
||||
except Exception:
|
||||
except Exception: # noqa: S110 — best-effort cleanup
|
||||
pass
|
||||
pooled.ref_count += 1
|
||||
pooled.last_used = time.monotonic()
|
||||
@@ -153,7 +153,7 @@ class AsyncSSHPool:
|
||||
if pooled:
|
||||
try:
|
||||
pooled.conn.close()
|
||||
except Exception:
|
||||
except Exception: # noqa: S110 — best-effort cleanup
|
||||
pass
|
||||
logger.debug(f"Force-closed SSH connection: server={server_id}")
|
||||
|
||||
@@ -190,7 +190,7 @@ class AsyncSSHPool:
|
||||
conn = await asyncssh.connect(**connect_kwargs)
|
||||
return conn
|
||||
except asyncssh.Error as e:
|
||||
raise ConnectionError(f"SSH connection failed to {server.domain}:{server.port}: {e}")
|
||||
raise ConnectionError(f"SSH connection failed to {server.domain}:{server.port}: {e}") from e
|
||||
|
||||
async def _evict_one(self) -> bool:
|
||||
"""Evict the oldest idle connection from the pool.
|
||||
@@ -209,7 +209,7 @@ class AsyncSSHPool:
|
||||
pooled = self._pool.pop(oldest_idle)
|
||||
try:
|
||||
pooled.conn.close()
|
||||
except Exception:
|
||||
except Exception: # noqa: S110 — best-effort cleanup
|
||||
pass
|
||||
logger.debug(f"Evicted idle SSH connection: server={oldest_idle}")
|
||||
return True
|
||||
@@ -233,7 +233,7 @@ class AsyncSSHPool:
|
||||
pooled = self._pool.pop(server_id)
|
||||
try:
|
||||
pooled.conn.close()
|
||||
except Exception:
|
||||
except Exception: # noqa: S110 — best-effort cleanup
|
||||
pass
|
||||
|
||||
if to_remove:
|
||||
|
||||
Reference in New Issue
Block a user