From 8afe3587ce4a69ff7319073bab2617546448d13a Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Freeman Date: Sun, 5 Apr 2026 17:52:50 +0000 Subject: [PATCH] fix(providers): remove type: ignore suppressions from registry.py and resolve underlying type errors Remove all 11 # type: ignore suppressions from src/cleveragents/providers/registry.py: - Resolve import-untyped suppressions (lines 529, 537, 545) for langchain_groq, langchain_together, and langchain_cohere by adding inline type stubs under typings/ following the existing pattern for langchain_anthropic and langchain_openai. - Remove arg-type suppressions (lines 475, 482, 490, 525, 533, 541, 549) from LLM constructor call sites. These were unnecessary given the pyrightconfig.json reportUnknown* settings already in place. - Fix the arg-type suppression on the llm_factory closure (line 657) by capturing the narrowed ProviderType in a local variable (resolved_provider_type: ProviderType) so Pyright can verify the type without suppression. Verified: nox -e typecheck passes with 0 errors, nox -e lint passes. Closes #3421 --- src/cleveragents/providers/registry.py | 30 ++++++++++++++----------- typings/langchain_cohere/__init__.pyi | 25 +++++++++++++++++++++ typings/langchain_groq/__init__.pyi | 25 +++++++++++++++++++++ typings/langchain_together/__init__.pyi | 25 +++++++++++++++++++++ 4 files changed, 92 insertions(+), 13 deletions(-) create mode 100644 typings/langchain_cohere/__init__.pyi create mode 100644 typings/langchain_groq/__init__.pyi create mode 100644 typings/langchain_together/__init__.pyi diff --git a/src/cleveragents/providers/registry.py b/src/cleveragents/providers/registry.py index 3723e9061..f606feef9 100644 --- a/src/cleveragents/providers/registry.py +++ b/src/cleveragents/providers/registry.py @@ -472,14 +472,14 @@ class ProviderRegistry: if provider_type == ProviderType.OPENAI: from langchain_openai import ChatOpenAI - return ChatOpenAI(model=model_id or "gpt-4o", **kwargs) # type: ignore[arg-type] + return ChatOpenAI(model=model_id or "gpt-4o", **kwargs) if provider_type == ProviderType.ANTHROPIC: from langchain_anthropic import ChatAnthropic return ChatAnthropic( model=model_id or "claude-sonnet-4-20250514", - **kwargs, # type: ignore[arg-type] + **kwargs, ) if provider_type in (ProviderType.GOOGLE, ProviderType.GEMINI): @@ -487,7 +487,7 @@ class ProviderRegistry: return ChatGoogleGenerativeAI( model=model_id or "gemini-2.0-flash", - **kwargs, # type: ignore[arg-type] + **kwargs, ) if provider_type == ProviderType.AZURE: @@ -522,31 +522,31 @@ class ProviderRegistry: deployment_name=deployment_name, azure_endpoint=azure_endpoint, api_version=api_version, - **kwargs, # type: ignore[arg-type] + **kwargs, ) if provider_type == ProviderType.GROQ: - from langchain_groq import ChatGroq # type: ignore[import-untyped] + from langchain_groq import ChatGroq return ChatGroq( model=model_id or "llama-3.1-70b-versatile", - **kwargs, # type: ignore[arg-type] + **kwargs, ) if provider_type == ProviderType.TOGETHER: - from langchain_together import ChatTogether # type: ignore[import-untyped] + from langchain_together import ChatTogether return ChatTogether( model=model_id or "meta-llama/Llama-3.1-70B-Instruct-Turbo", - **kwargs, # type: ignore[arg-type] + **kwargs, ) if provider_type == ProviderType.COHERE: - from langchain_cohere import ChatCohere # type: ignore[import-untyped] + from langchain_cohere import ChatCohere return ChatCohere( model=model_id or "command-r-plus", - **kwargs, # type: ignore[arg-type] + **kwargs, ) raise ValueError(f"Unsupported provider type: {provider_type}") @@ -647,14 +647,18 @@ class ProviderRegistry: max_retries=max_retries, ) - # Create factory function for the LLM + # Create factory function for the LLM. + # Capture the narrowed ProviderType in a local variable so the closure + # holds a ProviderType rather than the wider ProviderType | str | None. + resolved_provider_type: ProviderType = provider_type + def llm_factory(mid: str) -> BaseLanguageModel: factory_kwargs: dict[str, Any] = {"max_retries": max_retries} return self._create_provider_llm( - provider_type, + resolved_provider_type, mid, **factory_kwargs, - ) # type: ignore[arg-type] + ) return LangChainChatProvider( name=provider_type.value, diff --git a/typings/langchain_cohere/__init__.pyi b/typings/langchain_cohere/__init__.pyi new file mode 100644 index 000000000..a540af4b2 --- /dev/null +++ b/typings/langchain_cohere/__init__.pyi @@ -0,0 +1,25 @@ +"""Type stubs for langchain_cohere package.""" + +from typing import Any + +from langchain_core.language_models import BaseLanguageModel +from langchain_core.messages import AIMessage + +class ChatCohere(BaseLanguageModel[AIMessage]): + """Cohere chat model wrapper.""" + + def __init__( + self, + *, + model: str = ..., + temperature: float = ..., + max_tokens: int | None = None, + timeout: float | None = None, + max_retries: int = ..., + cohere_api_key: Any = None, + base_url: str | None = None, + streaming: bool = ..., + **kwargs: Any, + ) -> None: ... + +__all__ = ["ChatCohere"] diff --git a/typings/langchain_groq/__init__.pyi b/typings/langchain_groq/__init__.pyi new file mode 100644 index 000000000..c27b089d7 --- /dev/null +++ b/typings/langchain_groq/__init__.pyi @@ -0,0 +1,25 @@ +"""Type stubs for langchain_groq package.""" + +from typing import Any + +from langchain_core.language_models import BaseLanguageModel +from langchain_core.messages import AIMessage + +class ChatGroq(BaseLanguageModel[AIMessage]): + """Groq chat model wrapper.""" + + def __init__( + self, + *, + model: str = ..., + temperature: float = ..., + max_tokens: int | None = None, + timeout: float | None = None, + max_retries: int = ..., + api_key: Any = None, + base_url: str | None = None, + streaming: bool = ..., + **kwargs: Any, + ) -> None: ... + +__all__ = ["ChatGroq"] diff --git a/typings/langchain_together/__init__.pyi b/typings/langchain_together/__init__.pyi new file mode 100644 index 000000000..f93b96bcb --- /dev/null +++ b/typings/langchain_together/__init__.pyi @@ -0,0 +1,25 @@ +"""Type stubs for langchain_together package.""" + +from typing import Any + +from langchain_core.language_models import BaseLanguageModel +from langchain_core.messages import AIMessage + +class ChatTogether(BaseLanguageModel[AIMessage]): + """Together AI chat model wrapper.""" + + def __init__( + self, + *, + model: str = ..., + temperature: float = ..., + max_tokens: int | None = None, + timeout: float | None = None, + max_retries: int = ..., + api_key: Any = None, + base_url: str | None = None, + streaming: bool = ..., + **kwargs: Any, + ) -> None: ... + +__all__ = ["ChatTogether"] -- 2.52.0