From 7c224ebbd22a8d02da07c5b5ba4841fd84f8425d Mon Sep 17 00:00:00 2001 From: LIghtJUNction Date: Fri, 22 May 2026 15:23:24 +0800 Subject: [PATCH] ruff check && format --- astrbot/core/agent/run_context.py | 2 +- astrbot/core/computer/booters/boxlite.py | 10 +++++----- astrbot/core/computer/booters/shipyard_neo.py | 2 +- astrbot/core/platform/sources/lark/lark_event.py | 12 ++++++++---- astrbot/core/provider/sources/genie_tts.py | 2 +- astrbot/core/utils/io.py | 2 +- astrbot/dashboard/routes/stat.py | 6 ++++-- 7 files changed, 21 insertions(+), 15 deletions(-) diff --git a/astrbot/core/agent/run_context.py b/astrbot/core/agent/run_context.py index 42af22be1..1b1ef4ae8 100644 --- a/astrbot/core/agent/run_context.py +++ b/astrbot/core/agent/run_context.py @@ -13,7 +13,7 @@ TContext = TypeVar("TContext", default=Any) class ContextWrapper(Generic[TContext]): """A context for running an agent, which can be used to pass additional data or state.""" - context: TContext = cast(TContext, None) + context: TContext = cast("TContext", None) messages: list[Message] = Field(default_factory=list) """This field stores the llm message context for the agent run, agent runners will maintain this field automatically.""" tool_call_timeout: int = 120 # Default tool call timeout in seconds diff --git a/astrbot/core/computer/booters/boxlite.py b/astrbot/core/computer/booters/boxlite.py index 19c8d5eac..7ff965efa 100644 --- a/astrbot/core/computer/booters/boxlite.py +++ b/astrbot/core/computer/booters/boxlite.py @@ -199,22 +199,22 @@ class BoxliteBooter(ComputerBooter): sb_url=f"http://127.0.0.1:{random_port}", ) raw_fs = ShipyardFileSystemComponent( - client=cast(Any, self.mocked), + client=cast("Any", self.mocked), ship_id=self.box.id, session_id=session_id, ) self._python = ShipyardPythonComponent( - client=cast(Any, self.mocked), + client=cast("Any", self.mocked), ship_id=self.box.id, session_id=session_id, ) raw_shell = ShipyardShellComponent( - client=cast(Any, self.mocked), + client=cast("Any", self.mocked), ship_id=self.box.id, session_id=session_id, ) - self._shell = ShipyardShellWrapper(cast(Any, raw_shell)) - self._fs = ShipyardFileSystemWrapper(cast(Any, raw_fs), self._shell) + self._shell = ShipyardShellWrapper(cast("Any", raw_shell)) + self._fs = ShipyardFileSystemWrapper(cast("Any", raw_fs), self._shell) await self.mocked.wait_healthy(self.box.id, session_id) diff --git a/astrbot/core/computer/booters/shipyard_neo.py b/astrbot/core/computer/booters/shipyard_neo.py index 3b3007e3d..99340f6a5 100644 --- a/astrbot/core/computer/booters/shipyard_neo.py +++ b/astrbot/core/computer/booters/shipyard_neo.py @@ -223,7 +223,7 @@ class NeoFileSystemComponent(FileSystemComponent): ) -> dict[str, Any]: if self._shell is None: raise RuntimeError( - "NeoFileSystemComponent requires a shell for search_files." + "NeoFileSystemComponent requires a shell for search_files.", ) return await search_files_via_shell( self._shell, diff --git a/astrbot/core/platform/sources/lark/lark_event.py b/astrbot/core/platform/sources/lark/lark_event.py index 360dc53ee..f1e072e1d 100644 --- a/astrbot/core/platform/sources/lark/lark_event.py +++ b/astrbot/core/platform/sources/lark/lark_event.py @@ -668,7 +668,8 @@ class LarkMessageEvent(AstrMessageEvent): return if not original_audio_path or not await asyncio.to_thread( - os.path.exists, original_audio_path + os.path.exists, + original_audio_path, ): logger.error(f"[Lark] 音频文件不存在: {original_audio_path}") return @@ -700,7 +701,8 @@ class LarkMessageEvent(AstrMessageEvent): # 清理转换后的临时音频文件 if converted_audio_path and await asyncio.to_thread( - os.path.exists, converted_audio_path + os.path.exists, + converted_audio_path, ): try: await asyncio.to_thread(os.remove, converted_audio_path) @@ -746,7 +748,8 @@ class LarkMessageEvent(AstrMessageEvent): return if not original_video_path or not await asyncio.to_thread( - os.path.exists, original_video_path + os.path.exists, + original_video_path, ): logger.error(f"[Lark] 视频文件不存在: {original_video_path}") return @@ -778,7 +781,8 @@ class LarkMessageEvent(AstrMessageEvent): # 清理转换后的临时视频文件 if converted_video_path and await asyncio.to_thread( - os.path.exists, converted_video_path + os.path.exists, + converted_video_path, ): try: await asyncio.to_thread(os.remove, converted_video_path) diff --git a/astrbot/core/provider/sources/genie_tts.py b/astrbot/core/provider/sources/genie_tts.py index 2b72b6bee..2e83503e4 100644 --- a/astrbot/core/provider/sources/genie_tts.py +++ b/astrbot/core/provider/sources/genie_tts.py @@ -54,7 +54,7 @@ class GenieTTSProvider(TTSProvider): ) except Exception as e: raise RuntimeError( - f"Failed to load character {self.character_name}: {e}" + f"Failed to load character {self.character_name}: {e}", ) from e def support_stream(self) -> bool: diff --git a/astrbot/core/utils/io.py b/astrbot/core/utils/io.py index 9fd48225e..bc7cdcf85 100644 --- a/astrbot/core/utils/io.py +++ b/astrbot/core/utils/io.py @@ -198,7 +198,7 @@ async def download_file( start_time = time.time() if show_progress: logger.info( - f"Downloading: {url} | Size: {total_size / 1024:.2f} KB" + f"Downloading: {url} | Size: {total_size / 1024:.2f} KB", ) await _emit_download_progress( progress_callback, diff --git a/astrbot/dashboard/routes/stat.py b/astrbot/dashboard/routes/stat.py index 1c78ab5cf..f610f67de 100644 --- a/astrbot/dashboard/routes/stat.py +++ b/astrbot/dashboard/routes/stat.py @@ -498,10 +498,12 @@ class StatRoute(Route): # 验证最终路径在预期的 changelogs 目录内(防止路径遍历) # 确保规范化后的路径以 changelogs_dir 开头,且是目录内的文件 changelog_path_normalized = await asyncio.to_thread( - os.path.normpath, changelog_path + os.path.normpath, + changelog_path, ) changelogs_dir_normalized = await asyncio.to_thread( - os.path.normpath, changelogs_dir + os.path.normpath, + changelogs_dir, ) # 检查路径是否在预期目录内(必须是目录的子文件,不能是目录本身)