From b47dd2f923e50f3015574de13926632e4ee4badb Mon Sep 17 00:00:00 2001 From: Denis Shulyaka Date: Sat, 14 Feb 2026 22:04:29 +0300 Subject: [PATCH] Enable strict typing check for Anthropic (#163013) --- .strict-typing | 1 + homeassistant/components/anthropic/__init__.py | 4 ++-- homeassistant/components/anthropic/ai_task.py | 7 +++++-- homeassistant/components/anthropic/config_flow.py | 8 +++++--- homeassistant/components/anthropic/repairs.py | 9 ++++++--- mypy.ini | 10 ++++++++++ 6 files changed, 29 insertions(+), 10 deletions(-) diff --git a/.strict-typing b/.strict-typing index f2e2ba5301c..34961f012c0 100644 --- a/.strict-typing +++ b/.strict-typing @@ -84,6 +84,7 @@ homeassistant.components.androidtv_remote.* homeassistant.components.anel_pwrctrl.* homeassistant.components.anova.* homeassistant.components.anthemav.* +homeassistant.components.anthropic.* homeassistant.components.apache_kafka.* homeassistant.components.apcupsd.* homeassistant.components.api.* diff --git a/homeassistant/components/anthropic/__init__.py b/homeassistant/components/anthropic/__init__.py index 26f2f10a72f..9c01a9205ad 100644 --- a/homeassistant/components/anthropic/__init__.py +++ b/homeassistant/components/anthropic/__init__.py @@ -77,7 +77,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: AnthropicConfigEntry) -> return True -async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: +async def async_unload_entry(hass: HomeAssistant, entry: AnthropicConfigEntry) -> bool: """Unload Anthropic.""" return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) @@ -105,7 +105,7 @@ async def async_migrate_integration(hass: HomeAssistant) -> None: if not any(entry.version == 1 for entry in entries): return - api_keys_entries: dict[str, tuple[ConfigEntry, bool]] = {} + api_keys_entries: dict[str, tuple[AnthropicConfigEntry, bool]] = {} entity_registry = er.async_get(hass) device_registry = dr.async_get(hass) diff --git a/homeassistant/components/anthropic/ai_task.py b/homeassistant/components/anthropic/ai_task.py index d3536ec9bf4..34b2500e430 100644 --- a/homeassistant/components/anthropic/ai_task.py +++ b/homeassistant/components/anthropic/ai_task.py @@ -4,9 +4,9 @@ from __future__ import annotations from json import JSONDecodeError import logging +from typing import TYPE_CHECKING from homeassistant.components import ai_task, conversation -from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback @@ -14,12 +14,15 @@ from homeassistant.util.json import json_loads from .entity import AnthropicBaseLLMEntity +if TYPE_CHECKING: + from . import AnthropicConfigEntry + _LOGGER = logging.getLogger(__name__) async def async_setup_entry( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: AnthropicConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up AI Task entities.""" diff --git a/homeassistant/components/anthropic/config_flow.py b/homeassistant/components/anthropic/config_flow.py index 97514bc1f1c..89e6047e66a 100644 --- a/homeassistant/components/anthropic/config_flow.py +++ b/homeassistant/components/anthropic/config_flow.py @@ -5,7 +5,7 @@ from __future__ import annotations import json import logging import re -from typing import Any, cast +from typing import TYPE_CHECKING, Any, cast import anthropic import voluptuous as vol @@ -13,7 +13,6 @@ from voluptuous_openapi import convert from homeassistant.components.zone import ENTITY_ID_HOME from homeassistant.config_entries import ( - ConfigEntry, ConfigEntryState, ConfigFlow, ConfigFlowResult, @@ -65,6 +64,9 @@ from .const import ( WEB_SEARCH_UNSUPPORTED_MODELS, ) +if TYPE_CHECKING: + from . import AnthropicConfigEntry + _LOGGER = logging.getLogger(__name__) STEP_USER_DATA_SCHEMA = vol.Schema( @@ -188,7 +190,7 @@ class AnthropicConfigFlow(ConfigFlow, domain=DOMAIN): @classmethod @callback def async_get_supported_subentry_types( - cls, config_entry: ConfigEntry + cls, config_entry: AnthropicConfigEntry ) -> dict[str, type[ConfigSubentryFlow]]: """Return subentries supported by this integration.""" return { diff --git a/homeassistant/components/anthropic/repairs.py b/homeassistant/components/anthropic/repairs.py index 6240833568b..8f35fc548da 100644 --- a/homeassistant/components/anthropic/repairs.py +++ b/homeassistant/components/anthropic/repairs.py @@ -3,13 +3,13 @@ from __future__ import annotations from collections.abc import Iterator -from typing import cast +from typing import TYPE_CHECKING, cast import voluptuous as vol from homeassistant import data_entry_flow from homeassistant.components.repairs import RepairsFlow -from homeassistant.config_entries import ConfigEntry, ConfigEntryState, ConfigSubentry +from homeassistant.config_entries import ConfigEntryState, ConfigSubentry from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.selector import SelectSelector, SelectSelectorConfig @@ -23,6 +23,9 @@ from .const import ( DOMAIN, ) +if TYPE_CHECKING: + from . import AnthropicConfigEntry + class ModelDeprecatedRepairFlow(RepairsFlow): """Handler for an issue fixing flow.""" @@ -110,7 +113,7 @@ class ModelDeprecatedRepairFlow(RepairsFlow): async def _async_next_target( self, - ) -> tuple[ConfigEntry, ConfigSubentry, str] | None: + ) -> tuple[AnthropicConfigEntry, ConfigSubentry, str] | None: """Return the next deprecated subentry target.""" if self._subentry_iter is None: self._subentry_iter = self._iter_deprecated_subentries() diff --git a/mypy.ini b/mypy.ini index 35ca121906b..a98121fc0d8 100644 --- a/mypy.ini +++ b/mypy.ini @@ -595,6 +595,16 @@ disallow_untyped_defs = true warn_return_any = true warn_unreachable = true +[mypy-homeassistant.components.anthropic.*] +check_untyped_defs = true +disallow_incomplete_defs = true +disallow_subclassing_any = true +disallow_untyped_calls = true +disallow_untyped_decorators = true +disallow_untyped_defs = true +warn_return_any = true +warn_unreachable = true + [mypy-homeassistant.components.apache_kafka.*] check_untyped_defs = true disallow_incomplete_defs = true