chore(agents): 修 ruff 遗留问题(B904/SIM105/SIM117/I001)

provider.py 三处 except KeyError 后 raise 补 from None 阻断异常链;version.py
与 secrets.py 用 contextlib.suppress 替代 try-except-pass;test_cli.py 嵌套
with 合并;secrets.py/test_entrypoints.py 导入排序。
This commit is contained in:
Zhengshou Lai
2026-08-24 00:26:25 +08:00
parent 11a3efdd26
commit 20cd6c6b92
5 changed files with 13 additions and 13 deletions
+3 -3
View File
@@ -196,7 +196,7 @@ def provider_cmd(
known = ", ".join(p.id for p in list_providers())
raise click.ClickException(
f"Unknown provider '{provider_id}'. Choose from: {known}"
)
) from None
_do_switch(provider, key=key, model=model, base_url=base_url, yes=yes)
@@ -229,7 +229,7 @@ def provider_key_set(provider_id: str, key: str | None) -> None:
known = ", ".join(p.id for p in list_providers())
raise click.ClickException(
f"Unknown provider '{provider_id}'. Choose from: {known}"
)
) from None
if provider.id == "claude":
raise click.ClickException(
@@ -259,7 +259,7 @@ def provider_key_rm(provider_id: str, yes: bool) -> None:
known = ", ".join(p.id for p in list_providers())
raise click.ClickException(
f"Unknown provider '{provider_id}'. Choose from: {known}"
)
) from None
if not yes and not click.confirm(
f"Remove stored key for {provider.display_name}?",
+2 -3
View File
@@ -1,5 +1,6 @@
"""``version`` — show package install location."""
import contextlib
import shutil
import subprocess
from importlib.metadata import PackageNotFoundError, version
@@ -59,10 +60,8 @@ def version_cmd() -> None:
bin_path = shutil.which("myagents") or "?"
console.print(f"[bold]myagents[/bold] (bin: {bin_path})")
try:
with contextlib.suppress(PackageNotFoundError):
console.print(f" version: [cyan]{version('myagents')}[/cyan]")
except PackageNotFoundError:
pass
tree = _pkg_tree(myagents.__file__)
mode, detail = describe_tree(tree)
+2 -4
View File
@@ -13,6 +13,7 @@ keys shadow mytoolkit keys without modifying them.
from __future__ import annotations
import contextlib
import json
import os
import stat
@@ -20,7 +21,6 @@ import tempfile
from pathlib import Path
from typing import Any
XIAOHE_CONFIG_DIR = Path.home() / ".xiaohe" / "agent"
XIAOHE_CONFIG_PATH = XIAOHE_CONFIG_DIR / "config.json"
@@ -53,10 +53,8 @@ def _atomic_write(path: Path, data: dict[str, Any]) -> None:
os.chmod(tmp, stat.S_IRUSR | stat.S_IWUSR)
os.replace(tmp, path)
except Exception:
try:
with contextlib.suppress(OSError):
os.unlink(tmp)
except OSError:
pass
raise
+5 -3
View File
@@ -766,9 +766,11 @@ class TestDshListSessions:
}
),
]
with log.open("wb") as fh:
with zstd.ZstdCompressor().stream_writer(fh) as w:
w.write(("\n".join(lines) + "\n").encode("utf-8"))
with (
log.open("wb") as fh,
zstd.ZstdCompressor().stream_writer(fh) as w,
):
w.write(("\n".join(lines) + "\n").encode("utf-8"))
return log
def test_list_shows_dsh_sessions(self, tmp_path: Path, monkeypatch) -> None:
+1
View File
@@ -14,6 +14,7 @@ from myagents.entrypoints import (
kimi_cli,
)
class TestMyclaudeEntrypoint:
"""``myclaude`` standalone entrypoint."""