fix: resolve ty type error for asyncio.Lock private attribute access

Replace access to Lock._loop (private/unresolved attribute) with an explicit
_client_lock_loop field to track which event loop the lock belongs to.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
claude[bot] 2026-04-05 03:26:09 +00:00
parent 58ba1abba6
commit bb276b67e7

View file

@ -76,6 +76,7 @@ class LLMClient:
self.client_loop: asyncio.AbstractEventLoop | None = None
self.background_tasks: set[asyncio.Task[Any]] = set()
self._client_lock: asyncio.Lock | None = None
self._client_lock_loop: asyncio.AbstractEventLoop | None = None
async def call(
self,
@ -96,8 +97,9 @@ class LLMClient:
loop = asyncio.get_running_loop()
# Create lock for this event loop if it doesn't exist
if self._client_lock is None or self._client_lock._loop is not loop:
if self._client_lock is None or self._client_lock_loop is not loop:
self._client_lock = asyncio.Lock()
self._client_lock_loop = loop
if loop is not self.client_loop:
async with self._client_lock:
@ -110,14 +112,16 @@ class LLMClient:
await self.openai_client.close()
except Exception as e:
logger.debug(
"Failed to close OpenAI client (already closed or transport error): %s", type(e).__name__
"Failed to close OpenAI client (already closed or transport error): %s",
type(e).__name__,
)
if self.anthropic_client is not None:
try:
await self.anthropic_client.close()
except Exception as e:
logger.debug(
"Failed to close Anthropic client (already closed or transport error): %s", type(e).__name__
"Failed to close Anthropic client (already closed or transport error): %s",
type(e).__name__,
)
self.client_loop = loop