From 14e19c6d9cd6388af8b60575ff67aa27fe6d3972 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 23 Apr 2024 17:32:21 +0200 Subject: [PATCH] Remove unnecessary type ignores (#116036) --- homeassistant/components/alexa/intent.py | 8 +++++--- homeassistant/components/automation/logbook.py | 12 ++++++++++-- homeassistant/components/evohome/__init__.py | 8 ++++---- homeassistant/components/feedreader/__init__.py | 2 +- homeassistant/components/geniushub/water_heater.py | 4 ++-- homeassistant/components/group/notify.py | 4 ++-- homeassistant/components/input_text/__init__.py | 2 +- 7 files changed, 25 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/alexa/intent.py b/homeassistant/components/alexa/intent.py index fdf72ccce28..217d5dccc25 100644 --- a/homeassistant/components/alexa/intent.py +++ b/homeassistant/components/alexa/intent.py @@ -1,5 +1,6 @@ """Support for Alexa skill service end point.""" +from collections.abc import Callable, Coroutine import enum import logging from typing import Any @@ -16,7 +17,9 @@ from .const import DOMAIN, SYN_RESOLUTION_MATCH _LOGGER = logging.getLogger(__name__) -HANDLERS = Registry() # type: ignore[var-annotated] +HANDLERS: Registry[ + str, Callable[[HomeAssistant, dict[str, Any]], Coroutine[Any, Any, dict[str, Any]]] +] = Registry() INTENTS_API_ENDPOINT = "/api/alexa" @@ -129,8 +132,7 @@ async def async_handle_message( if not (handler := HANDLERS.get(req_type)): raise UnknownRequest(f"Received unknown request {req_type}") - response: dict[str, Any] = await handler(hass, message) - return response + return await handler(hass, message) @HANDLERS.register("SessionEndedRequest") diff --git a/homeassistant/components/automation/logbook.py b/homeassistant/components/automation/logbook.py index 7b9c8cf5809..33ed586f901 100644 --- a/homeassistant/components/automation/logbook.py +++ b/homeassistant/components/automation/logbook.py @@ -1,5 +1,8 @@ """Describe logbook events.""" +from collections.abc import Callable +from typing import Any + from homeassistant.components.logbook import ( LOGBOOK_ENTRY_CONTEXT_ID, LOGBOOK_ENTRY_ENTITY_ID, @@ -16,11 +19,16 @@ from .const import DOMAIN @callback -def async_describe_events(hass: HomeAssistant, async_describe_event): # type: ignore[no-untyped-def] +def async_describe_events( + hass: HomeAssistant, + async_describe_event: Callable[ + [str, str, Callable[[LazyEventPartialState], dict[str, Any]]], None + ], +) -> None: """Describe logbook events.""" @callback - def async_describe_logbook_event(event: LazyEventPartialState): # type: ignore[no-untyped-def] + def async_describe_logbook_event(event: LazyEventPartialState) -> dict[str, Any]: """Describe a logbook event.""" data = event.data message = "triggered" diff --git a/homeassistant/components/evohome/__init__.py b/homeassistant/components/evohome/__init__.py index 49920d79ff3..4564e863e42 100644 --- a/homeassistant/components/evohome/__init__.py +++ b/homeassistant/components/evohome/__init__.py @@ -33,7 +33,7 @@ from evohomeasync2.schema.const import ( SZ_TIMING_MODE, SZ_UNTIL, ) -import voluptuous as vol # type: ignore[import-untyped] +import voluptuous as vol from homeassistant.const import ( ATTR_ENTITY_ID, @@ -462,7 +462,7 @@ class EvoBroker: self.client.access_token_expires # type: ignore[arg-type] ) - app_storage = { + app_storage: dict[str, Any] = { CONF_USERNAME: self.client.username, REFRESH_TOKEN: self.client.refresh_token, ACCESS_TOKEN: self.client.access_token, @@ -470,11 +470,11 @@ class EvoBroker: } if self.client_v1: - app_storage[USER_DATA] = { # type: ignore[assignment] + app_storage[USER_DATA] = { SZ_SESSION_ID: self.client_v1.broker.session_id, } # this is the schema for STORAGE_VER == 1 else: - app_storage[USER_DATA] = {} # type: ignore[assignment] + app_storage[USER_DATA] = {} await self._store.async_save(app_storage) diff --git a/homeassistant/components/feedreader/__init__.py b/homeassistant/components/feedreader/__init__.py index 0a16e986d0b..2b0c6b77559 100644 --- a/homeassistant/components/feedreader/__init__.py +++ b/homeassistant/components/feedreader/__init__.py @@ -117,7 +117,7 @@ class FeedManager: def _update(self) -> struct_time | None: """Update the feed and publish new entries to the event bus.""" _LOGGER.debug("Fetching new data from feed %s", self._url) - self._feed: feedparser.FeedParserDict = feedparser.parse( # type: ignore[no-redef] + self._feed = feedparser.parse( self._url, etag=None if not self._feed else self._feed.get("etag"), modified=None if not self._feed else self._feed.get("modified"), diff --git a/homeassistant/components/geniushub/water_heater.py b/homeassistant/components/geniushub/water_heater.py index 6c3b5223ef9..f17560ebc62 100644 --- a/homeassistant/components/geniushub/water_heater.py +++ b/homeassistant/components/geniushub/water_heater.py @@ -75,9 +75,9 @@ class GeniusWaterHeater(GeniusHeatingZone, WaterHeaterEntity): return list(HA_OPMODE_TO_GH) @property - def current_operation(self) -> str: + def current_operation(self) -> str | None: """Return the current operation mode.""" - return GH_STATE_TO_HA[self._zone.data["mode"]] # type: ignore[return-value] + return GH_STATE_TO_HA[self._zone.data["mode"]] async def async_set_operation_mode(self, operation_mode: str) -> None: """Set a new operation mode for this boiler.""" diff --git a/homeassistant/components/group/notify.py b/homeassistant/components/group/notify.py index bad3d7944d3..425dcf5a914 100644 --- a/homeassistant/components/group/notify.py +++ b/homeassistant/components/group/notify.py @@ -34,12 +34,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( def add_defaults( - input_data: dict[str, Any], default_data: dict[str, Any] + input_data: dict[str, Any], default_data: Mapping[str, Any] ) -> dict[str, Any]: """Deep update a dictionary with default values.""" for key, val in default_data.items(): if isinstance(val, Mapping): - input_data[key] = add_defaults(input_data.get(key, {}), val) # type: ignore[arg-type] + input_data[key] = add_defaults(input_data.get(key, {}), val) elif key not in input_data: input_data[key] = val return input_data diff --git a/homeassistant/components/input_text/__init__.py b/homeassistant/components/input_text/__init__.py index 52788066ba2..55b43ee8a1e 100644 --- a/homeassistant/components/input_text/__init__.py +++ b/homeassistant/components/input_text/__init__.py @@ -264,7 +264,7 @@ class InputText(collection.CollectionEntity, RestoreEntity): return state = await self.async_get_last_state() - value: str | None = state and state.state # type: ignore[assignment] + value = state.state if state else None # Check against None because value can be 0 if value is not None and self._minimum <= len(value) <= self._maximum: