From 827cb8eb2f85833d7c72775d30f07c5261cb464f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 12 Jun 2026 17:42:15 +0000 Subject: [PATCH] Refactor `GenAIClient` import in `frigate/genai/manager.py` to fix unused import warning The linter flagged `GenAIClient` as an unused import because it was only referenced inside string literals (`"GenAIClient"`) for forward referencing in type hints. Instead of removing the import and substituting it with `Any`, this adds `from __future__ import annotations` and removes the string quotes from the type hints. This resolves the linter warning by directly associating the imported symbol with the types, while fully preserving strict typing and the benefits of lazily evaluating `GenAIClient` via `TYPE_CHECKING` to prevent circular imports. Co-authored-by: manupawickramasinghe <73810867+manupawickramasinghe@users.noreply.github.com> --- frigate/genai/manager.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/frigate/genai/manager.py b/frigate/genai/manager.py index a1325d3279..e8d1d87b69 100644 --- a/frigate/genai/manager.py +++ b/frigate/genai/manager.py @@ -5,6 +5,8 @@ no chat feature is active) are never initialized. """ +from __future__ import annotations + import logging from typing import TYPE_CHECKING, Any, Optional @@ -23,7 +25,7 @@ class GenAIClientManager: def __init__(self, config: FrigateConfig) -> None: self._configs: dict[str, GenAIConfig] = {} self._role_map: dict[GenAIRoleEnum, str] = {} - self._clients: dict[str, "GenAIClient"] = {} + self._clients: dict[str, GenAIClient] = {} self.update_config(config) def update_config(self, config: FrigateConfig) -> None: @@ -59,7 +61,7 @@ def update_config(self, config: FrigateConfig) -> None: for role in genai_cfg.roles: self._role_map[role] = name - def _get_client(self, name: str) -> "Optional[GenAIClient]": + def _get_client(self, name: str) -> Optional[GenAIClient]: """Return the client for *name*, creating it on first access.""" if name in self._clients: return self._clients[name] @@ -78,7 +80,7 @@ def _get_client(self, name: str) -> "Optional[GenAIClient]": return None try: - client: "GenAIClient" = provider_cls(genai_cfg) + client: GenAIClient = provider_cls(genai_cfg) except Exception as e: logger.exception( "Failed to create GenAI client for provider %s: %s", @@ -91,19 +93,19 @@ def _get_client(self, name: str) -> "Optional[GenAIClient]": return client @property - def chat_client(self) -> "Optional[GenAIClient]": + def chat_client(self) -> Optional[GenAIClient]: """Client configured for the chat role (e.g. chat with function calling).""" name = self._role_map.get(GenAIRoleEnum.chat) return self._get_client(name) if name else None @property - def description_client(self) -> "Optional[GenAIClient]": + def description_client(self) -> Optional[GenAIClient]: """Client configured for the descriptions role (e.g. review descriptions, object descriptions).""" name = self._role_map.get(GenAIRoleEnum.descriptions) return self._get_client(name) if name else None @property - def embeddings_client(self) -> "Optional[GenAIClient]": + def embeddings_client(self) -> Optional[GenAIClient]: """Client configured for the embeddings role.""" name = self._role_map.get(GenAIRoleEnum.embeddings) return self._get_client(name) if name else None