From 804a02a2d1f4126cf4c63d9c415e2c78543deb33 Mon Sep 17 00:00:00 2001 From: LIghtJUNction Date: Fri, 20 Mar 2026 16:36:22 +0800 Subject: [PATCH] fix(types): await anyio.open_file before async use to satisfy type checkers --- astrbot/core/utils/astrbot_path.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/astrbot/core/utils/astrbot_path.py b/astrbot/core/utils/astrbot_path.py index b4dadee96..d2538288b 100644 --- a/astrbot/core/utils/astrbot_path.py +++ b/astrbot/core/utils/astrbot_path.py @@ -121,12 +121,20 @@ class AstrbotPaths: async def async_dashboard_version(self) -> str | None: try: - # Use async context manager to open and read the file asynchronously. - async with anyio.open_file(self.dist / "assets" / "version", mode="r") as f: + # anyio.open_file returns a coroutine that yields an async file object. + # Await it to get the file object, then use it and close it explicitly. + f = await anyio.open_file(self.dist / "assets" / "version", mode="r") + try: data = await f.read() if data is None: return None return data.strip() + finally: + # Ensure we close the async file handle; ignore close errors defensively. + try: + await f.aclose() + except Exception: + pass except (FileNotFoundError, OSError): return None except Exception: