Skip to content

Commit 8b6d235

Browse files
committed
chore(cli): add missing type annotations
1 parent c530489 commit 8b6d235

File tree

6 files changed

+24
-18
lines changed

6 files changed

+24
-18
lines changed

astrbot/cli/commands/cmd_conf.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def _save_config(config: dict[str, Any]) -> None:
102102
)
103103

104104

105-
def _set_nested_item(obj: dict[str, Any], path: str, value: Any) -> None:
105+
def _set_nested_item(obj: dict[str, Any], path: str, value: object) -> None:
106106
"""设置嵌套字典中的值"""
107107
parts = path.split(".")
108108
for part in parts[:-1]:
@@ -116,7 +116,7 @@ def _set_nested_item(obj: dict[str, Any], path: str, value: Any) -> None:
116116
obj[parts[-1]] = value
117117

118118

119-
def _get_nested_item(obj: dict[str, Any], path: str) -> Any:
119+
def _get_nested_item(obj: dict[str, Any], path: str) -> object:
120120
"""获取嵌套字典中的值"""
121121
parts = path.split(".")
122122
for part in parts:
@@ -125,7 +125,7 @@ def _get_nested_item(obj: dict[str, Any], path: str) -> Any:
125125

126126

127127
@click.group(name="conf")
128-
def conf():
128+
def conf() -> None:
129129
"""配置管理命令
130130
131131
支持的配置项:
@@ -148,7 +148,7 @@ def conf():
148148
@conf.command(name="set")
149149
@click.argument("key")
150150
@click.argument("value")
151-
def set_config(key: str, value: str):
151+
def set_config(key: str, value: str) -> None:
152152
"""设置配置项的值"""
153153
if key not in CONFIG_VALIDATORS.keys():
154154
raise click.ClickException(f"不支持的配置项: {key}")
@@ -177,7 +177,7 @@ def set_config(key: str, value: str):
177177

178178
@conf.command(name="get")
179179
@click.argument("key", required=False)
180-
def get_config(key: str = None):
180+
def get_config(key: str | None = None) -> None:
181181
"""获取配置项的值,不提供key则显示所有可配置项"""
182182
config = _load_config()
183183

astrbot/cli/commands/cmd_init.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from pathlib import Path
2+
13
import asyncio
24

35
import click
@@ -6,7 +8,7 @@
68
from ..utils import check_dashboard, get_astrbot_root
79

810

9-
async def initialize_astrbot(astrbot_root) -> None:
11+
async def initialize_astrbot(astrbot_root: Path) -> None:
1012
"""执行 AstrBot 初始化逻辑"""
1113
dot_astrbot = astrbot_root / ".astrbot"
1214

astrbot/cli/commands/cmd_plug.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
@click.group()
19-
def plug():
19+
def plug() -> None:
2020
"""插件管理"""
2121
pass
2222

@@ -30,7 +30,11 @@ def _get_data_path() -> Path:
3030
return (base / "data").resolve()
3131

3232

33-
def display_plugins(plugins, title=None, color=None):
33+
def display_plugins(
34+
plugins: list[dict],
35+
title: str | None = None,
36+
color: int | tuple[int, int, int] | str | None = None,
37+
) -> None:
3438
if title:
3539
click.echo(click.style(title, fg=color, bold=True))
3640

@@ -47,7 +51,7 @@ def display_plugins(plugins, title=None, color=None):
4751

4852
@plug.command()
4953
@click.argument("name")
50-
def new(name: str):
54+
def new(name: str) -> None:
5155
"""创建新插件"""
5256
base_path = _get_data_path()
5357
plug_path = base_path / "plugins" / name
@@ -102,7 +106,7 @@ def new(name: str):
102106

103107
@plug.command()
104108
@click.option("--all", "-a", is_flag=True, help="列出未安装的插件")
105-
def list(all: bool):
109+
def list(all: bool) -> None:
106110
"""列出插件"""
107111
base_path = _get_data_path()
108112
plugins = build_plug_list(base_path / "plugins")
@@ -143,7 +147,7 @@ def list(all: bool):
143147
@plug.command()
144148
@click.argument("name")
145149
@click.option("--proxy", help="代理服务器地址")
146-
def install(name: str, proxy: str | None):
150+
def install(name: str, proxy: str | None) -> None:
147151
"""安装插件"""
148152
base_path = _get_data_path()
149153
plug_path = base_path / "plugins"
@@ -166,7 +170,7 @@ def install(name: str, proxy: str | None):
166170

167171
@plug.command()
168172
@click.argument("name")
169-
def remove(name: str):
173+
def remove(name: str) -> None:
170174
"""卸载插件"""
171175
base_path = _get_data_path()
172176
plugins = build_plug_list(base_path / "plugins")
@@ -189,7 +193,7 @@ def remove(name: str):
189193
@plug.command()
190194
@click.argument("name", required=False)
191195
@click.option("--proxy", help="Github代理地址")
192-
def update(name: str, proxy: str | None):
196+
def update(name: str, proxy: str | None) -> None:
193197
"""更新插件"""
194198
base_path = _get_data_path()
195199
plug_path = base_path / "plugins"
@@ -227,7 +231,7 @@ def update(name: str, proxy: str | None):
227231

228232
@plug.command()
229233
@click.argument("query")
230-
def search(query: str):
234+
def search(query: str) -> None:
231235
"""搜索插件"""
232236
base_path = _get_data_path()
233237
plugins = build_plug_list(base_path / "plugins")

astrbot/cli/commands/cmd_run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from ..utils import check_dashboard, check_astrbot_root, get_astrbot_root
1212

1313

14-
async def run_astrbot(astrbot_root: Path):
14+
async def run_astrbot(astrbot_root: Path) -> None:
1515
"""运行 AstrBot"""
1616
from astrbot.core import logger, LogManager, LogBroker, db_helper
1717
from astrbot.core.initial_loader import InitialLoader

astrbot/cli/utils/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class PluginStatus(str, Enum):
1919
NOT_PUBLISHED = "未发布"
2020

2121

22-
def get_git_repo(url: str, target_path: Path, proxy: str | None = None):
22+
def get_git_repo(url: str, target_path: Path, proxy: str | None = None) -> None:
2323
"""从 Git 仓库下载代码并解压到指定路径"""
2424
temp_dir = Path(tempfile.mkdtemp())
2525
try:

astrbot/cli/utils/version_comparator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def compare_version(v1: str, v2: str) -> int:
1717
v1 = v1.lower().replace("v", "")
1818
v2 = v2.lower().replace("v", "")
1919

20-
def split_version(version):
20+
def split_version(version: str) -> tuple[list[int], list[int | str] | None]:
2121
match = re.match(
2222
r"^([0-9]+(?:\.[0-9]+)*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+(.+))?$",
2323
version,
@@ -79,7 +79,7 @@ def split_version(version):
7979
return 0 # 数字部分和预发布标签都相同
8080

8181
@staticmethod
82-
def _split_prerelease(prerelease):
82+
def _split_prerelease(prerelease: str) -> list[int | str] | None:
8383
if not prerelease:
8484
return None
8585
parts = prerelease.split(".")

0 commit comments

Comments
 (0)