diff --git a/homeassistant/components/actiontec/const.py b/homeassistant/components/actiontec/const.py index 1043bd1bdb6..de309b68476 100644 --- a/homeassistant/components/actiontec/const.py +++ b/homeassistant/components/actiontec/const.py @@ -4,7 +4,9 @@ from __future__ import annotations import re from typing import Final -LEASES_REGEX: Final[re.Pattern] = re.compile( +# mypy: disallow-any-generics + +LEASES_REGEX: Final[re.Pattern[str]] = re.compile( r"(?P([0-9]{1,3}[\.]){3}[0-9]{1,3})" + r"\smac:\s(?P([0-9a-f]{2}[:-]){5}([0-9a-f]{2}))" + r"\svalid\sfor:\s(?P(-?\d+))" diff --git a/homeassistant/components/hassio/discovery.py b/homeassistant/components/hassio/discovery.py index e7f8df3b61d..9f15ff6e8b8 100644 --- a/homeassistant/components/hassio/discovery.py +++ b/homeassistant/components/hassio/discovery.py @@ -8,7 +8,7 @@ from aiohttp.web_exceptions import HTTPServiceUnavailable from homeassistant import config_entries from homeassistant.components.http import HomeAssistantView from homeassistant.const import ATTR_NAME, ATTR_SERVICE, EVENT_HOMEASSISTANT_START -from homeassistant.core import callback +from homeassistant.core import HomeAssistant, callback from .const import ATTR_ADDON, ATTR_CONFIG, ATTR_DISCOVERY, ATTR_UUID from .handler import HassioAPIError @@ -17,7 +17,7 @@ _LOGGER = logging.getLogger(__name__) @callback -def async_setup_discovery_view(hass: HomeAssistantView, hassio): +def async_setup_discovery_view(hass: HomeAssistant, hassio): """Discovery setup.""" hassio_discovery = HassIODiscovery(hass, hassio) hass.http.register_view(hassio_discovery) @@ -49,7 +49,7 @@ class HassIODiscovery(HomeAssistantView): name = "api:hassio_push:discovery" url = "/api/hassio_push/discovery/{uuid}" - def __init__(self, hass: HomeAssistantView, hassio): + def __init__(self, hass: HomeAssistant, hassio): """Initialize WebView.""" self.hass = hass self.hassio = hassio diff --git a/homeassistant/components/http/view.py b/homeassistant/components/http/view.py index 9abf0914b06..129c43600c4 100644 --- a/homeassistant/components/http/view.py +++ b/homeassistant/components/http/view.py @@ -158,7 +158,7 @@ def request_handler_factory( else: assert ( False - ), f"Result should be None, string, bytes or Response. Got: {result}" + ), f"Result should be None, string, bytes or StreamResponse. Got: {result}" return web.Response(body=bresult, status=status_code) diff --git a/homeassistant/helpers/condition.py b/homeassistant/helpers/condition.py index 6f5e7c40d22..f90086f87ee 100644 --- a/homeassistant/helpers/condition.py +++ b/homeassistant/helpers/condition.py @@ -69,6 +69,8 @@ from .trace import ( trace_stack_top, ) +# mypy: disallow-any-generics + FROM_CONFIG_FORMAT = "{}_from_config" ASYNC_FROM_CONFIG_FORMAT = "async_{}_from_config" @@ -113,7 +115,7 @@ def condition_trace_update_result(**kwargs: Any) -> None: @contextmanager -def trace_condition(variables: TemplateVarsType) -> Generator: +def trace_condition(variables: TemplateVarsType) -> Generator[TraceElement, None, None]: """Trace condition evaluation.""" should_pop = True trace_element = trace_stack_top(trace_stack_cv) diff --git a/homeassistant/helpers/event.py b/homeassistant/helpers/event.py index ab54d159f5e..5d5f71d2fd5 100644 --- a/homeassistant/helpers/event.py +++ b/homeassistant/helpers/event.py @@ -71,8 +71,8 @@ class TrackStates: """ all_states: bool - entities: set - domains: set + entities: set[str] + domains: set[str] @dataclass @@ -394,7 +394,7 @@ def async_track_entity_registry_updated_event( @callback def _async_dispatch_domain_event( - hass: HomeAssistant, event: Event, callbacks: dict[str, list] + hass: HomeAssistant, event: Event, callbacks: dict[str, list[HassJob]] ) -> None: domain = split_entity_id(event.data["entity_id"])[0] @@ -620,7 +620,7 @@ class _TrackStateChangeFiltered: self._listeners.pop(listener_name)() @callback - def _setup_entities_listener(self, domains: set, entities: set) -> None: + def _setup_entities_listener(self, domains: set[str], entities: set[str]) -> None: if domains: entities = entities.copy() entities.update(self.hass.states.async_entity_ids(domains)) @@ -634,7 +634,7 @@ class _TrackStateChangeFiltered: ) @callback - def _setup_domains_listener(self, domains: set) -> None: + def _setup_domains_listener(self, domains: set[str]) -> None: if not domains: return diff --git a/homeassistant/helpers/trace.py b/homeassistant/helpers/trace.py index e25cf814b2a..58b0dc19d43 100644 --- a/homeassistant/helpers/trace.py +++ b/homeassistant/helpers/trace.py @@ -21,7 +21,7 @@ class TraceElement: self._child_run_id: str | None = None self._error: Exception | None = None self.path: str = path - self._result: dict | None = None + self._result: dict[str, Any] | None = None self.reuse_by_child = False self._timestamp = dt_util.utcnow() diff --git a/homeassistant/helpers/translation.py b/homeassistant/helpers/translation.py index a77cf3c2227..e10c814389b 100644 --- a/homeassistant/helpers/translation.py +++ b/homeassistant/helpers/translation.py @@ -17,6 +17,8 @@ from homeassistant.loader import ( from homeassistant.util.async_ import gather_with_concurrency from homeassistant.util.json import load_json +# mypy: disallow-any-generics + _LOGGER = logging.getLogger(__name__) TRANSLATION_LOAD_LOCK = "translation_load_lock" @@ -24,7 +26,7 @@ TRANSLATION_FLATTEN_CACHE = "translation_flatten_cache" LOCALE_EN = "en" -def recursive_flatten(prefix: Any, data: dict) -> dict[str, Any]: +def recursive_flatten(prefix: Any, data: dict[str, Any]) -> dict[str, Any]: """Return a flattened representation of dict data.""" output = {} for key, value in data.items(): @@ -212,7 +214,7 @@ class _TranslationCache: self, language: str, category: str, - components: set, + components: set[str], ) -> list[dict[str, dict[str, Any]]]: """Load resources into the cache.""" components_to_load = components - self.loaded.setdefault(language, set()) @@ -224,7 +226,7 @@ class _TranslationCache: return [cached.get(component, {}).get(category, {}) for component in components] - async def _async_load(self, language: str, components: set) -> None: + async def _async_load(self, language: str, components: set[str]) -> None: """Populate the cache for a given set of components.""" _LOGGER.debug( "Cache miss for %s: %s", @@ -247,7 +249,7 @@ class _TranslationCache: def _build_category_cache( self, language: str, - components: set, + components: set[str], translation_strings: dict[str, dict[str, Any]], ) -> None: """Extract resources into the cache."""