diff --git a/homeassistant/helpers/aiohttp_client.py b/homeassistant/helpers/aiohttp_client.py index 65b1b657ef4..eaabb002b0a 100644 --- a/homeassistant/helpers/aiohttp_client.py +++ b/homeassistant/helpers/aiohttp_client.py @@ -104,9 +104,9 @@ def _async_create_clientsession( # If a package requires a different user agent, override it by passing a headers # dictionary to the request method. # pylint: disable=protected-access - clientsession._default_headers = MappingProxyType({USER_AGENT: SERVER_SOFTWARE}) # type: ignore + clientsession._default_headers = MappingProxyType({USER_AGENT: SERVER_SOFTWARE}) # type: ignore[assignment] - clientsession.close = warn_use(clientsession.close, WARN_CLOSE_MSG) # type: ignore + clientsession.close = warn_use(clientsession.close, WARN_CLOSE_MSG) # type: ignore[assignment] if auto_cleanup_method: auto_cleanup_method(hass, clientsession) diff --git a/homeassistant/helpers/config_entry_oauth2_flow.py b/homeassistant/helpers/config_entry_oauth2_flow.py index 04e11ab99be..cf2d73715de 100644 --- a/homeassistant/helpers/config_entry_oauth2_flow.py +++ b/homeassistant/helpers/config_entry_oauth2_flow.py @@ -217,7 +217,7 @@ class AbstractOAuth2FlowHandler(config_entries.ConfigFlow, metaclass=ABCMeta): ) self.external_data: Any = None - self.flow_impl: AbstractOAuth2Implementation = None # type: ignore + self.flow_impl: AbstractOAuth2Implementation = None # type: ignore[assignment] @property @abstractmethod diff --git a/homeassistant/helpers/config_validation.py b/homeassistant/helpers/config_validation.py index cbd1f4ffaba..05f16bc06ad 100644 --- a/homeassistant/helpers/config_validation.py +++ b/homeassistant/helpers/config_validation.py @@ -15,7 +15,9 @@ import logging from numbers import Number import os import re -from socket import _GLOBAL_DEFAULT_TIMEOUT # type: ignore # private, not in typeshed +from socket import ( # type: ignore[attr-defined] # private, not in typeshed + _GLOBAL_DEFAULT_TIMEOUT, +) from typing import Any, TypeVar, cast, overload from urllib.parse import urlparse from uuid import UUID @@ -163,7 +165,7 @@ def boolean(value: Any) -> bool: return False elif isinstance(value, Number): # type ignore: https://github.com/python/mypy/issues/3186 - return value != 0 # type: ignore + return value != 0 # type: ignore[comparison-overlap] raise vol.Invalid(f"invalid boolean value {value}") @@ -421,7 +423,7 @@ def date(value: Any) -> date_sys: def time_period_str(value: str) -> timedelta: """Validate and transform time offset.""" - if isinstance(value, int): # type: ignore + if isinstance(value, int): # type: ignore[unreachable] raise vol.Invalid("Make sure you wrap time values in quotes") if not isinstance(value, str): raise vol.Invalid(TIME_PERIOD_ERROR.format(value)) @@ -585,7 +587,7 @@ def template(value: Any | None) -> template_helper.Template: if isinstance(value, (list, dict, template_helper.Template)): raise vol.Invalid("template value should be a string") - template_value = template_helper.Template(str(value)) # type: ignore + template_value = template_helper.Template(str(value)) # type: ignore[no-untyped-call] try: template_value.ensure_valid() @@ -603,7 +605,7 @@ def dynamic_template(value: Any | None) -> template_helper.Template: if not template_helper.is_template_string(str(value)): raise vol.Invalid("template value does not contain a dynamic template") - template_value = template_helper.Template(str(value)) # type: ignore + template_value = template_helper.Template(str(value)) # type: ignore[no-untyped-call] try: template_value.ensure_valid() return template_value @@ -796,7 +798,7 @@ def _deprecated_or_removed( """Check if key is in config and log warning or error.""" if key in config: try: - near = f"near {config.__config_file__}:{config.__line__} " # type: ignore + near = f"near {config.__config_file__}:{config.__line__} " # type: ignore[attr-defined] except AttributeError: near = "" arguments: tuple[str, ...] diff --git a/homeassistant/helpers/data_entry_flow.py b/homeassistant/helpers/data_entry_flow.py index 09345bf51bf..07f5e640ea3 100644 --- a/homeassistant/helpers/data_entry_flow.py +++ b/homeassistant/helpers/data_entry_flow.py @@ -70,7 +70,7 @@ class FlowManagerIndexView(_BaseFlowManagerView): try: result = await self._flow_mgr.async_init( - handler, # type: ignore + handler, # type: ignore[arg-type] context={ "source": config_entries.SOURCE_USER, "show_advanced_options": data["show_advanced_options"], diff --git a/homeassistant/helpers/debounce.py b/homeassistant/helpers/debounce.py index e3f13e3ad16..7937459b50c 100644 --- a/homeassistant/helpers/debounce.py +++ b/homeassistant/helpers/debounce.py @@ -97,7 +97,7 @@ class Debouncer: async with self._execute_lock: # Abort if timer got set while we're waiting for the lock. if self._timer_task: - return # type: ignore + return # type: ignore[unreachable] try: task = self.hass.async_run_hass_job(self._job) diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index bf2e13c1e24..bb600556991 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -255,12 +255,12 @@ class Entity(ABC): # SAFE TO OVERWRITE # The properties and methods here are safe to overwrite when inheriting # this class. These may be used to customize the behavior of the entity. - entity_id: str = None # type: ignore + entity_id: str = None # type: ignore[assignment] # Owning hass instance. Will be set by EntityPlatform # While not purely typed, it makes typehinting more useful for us # and removes the need for constant None checks or asserts. - hass: HomeAssistant = None # type: ignore + hass: HomeAssistant = None # type: ignore[assignment] # Owning platform instance. Will be set by EntityPlatform platform: EntityPlatform | None = None @@ -770,7 +770,7 @@ class Entity(ABC): @callback def add_to_platform_abort(self) -> None: """Abort adding an entity to a platform.""" - self.hass = None # type: ignore + self.hass = None # type: ignore[assignment] self.platform = None self.parallel_updates = None self._added = False diff --git a/homeassistant/helpers/httpx_client.py b/homeassistant/helpers/httpx_client.py index d1dc11aae4d..e2ebbd31dac 100644 --- a/homeassistant/helpers/httpx_client.py +++ b/homeassistant/helpers/httpx_client.py @@ -71,7 +71,7 @@ def create_async_httpx_client( original_aclose = client.aclose - client.aclose = warn_use( # type: ignore + client.aclose = warn_use( # type: ignore[assignment] client.aclose, "closes the Home Assistant httpx client" ) diff --git a/homeassistant/helpers/intent.py b/homeassistant/helpers/intent.py index 13cc32a35b6..44dd21d7fa3 100644 --- a/homeassistant/helpers/intent.py +++ b/homeassistant/helpers/intent.py @@ -152,7 +152,7 @@ class IntentHandler: extra=vol.ALLOW_EXTRA, ) - return self._slot_schema(slots) # type: ignore + return self._slot_schema(slots) # type: ignore[no-any-return] async def async_handle(self, intent_obj: Intent) -> IntentResponse: """Handle the intent.""" diff --git a/homeassistant/helpers/location.py b/homeassistant/helpers/location.py index 06fb0760818..bbc32145706 100644 --- a/homeassistant/helpers/location.py +++ b/homeassistant/helpers/location.py @@ -68,11 +68,11 @@ def find_coordinates( # Check if entity_state is a zone zone_entity = hass.states.get(f"zone.{entity_state.state}") - if has_location(zone_entity): # type: ignore + if has_location(zone_entity): # type: ignore[arg-type] _LOGGER.debug( - "%s is in %s, getting zone location", name, zone_entity.entity_id # type: ignore + "%s is in %s, getting zone location", name, zone_entity.entity_id # type: ignore[union-attr] ) - return _get_location_from_attributes(zone_entity) # type: ignore + return _get_location_from_attributes(zone_entity) # type: ignore[arg-type] # Check if entity_state is a friendly name of a zone if (zone_coords := resolve_zone(hass, entity_state.state)) is not None: diff --git a/homeassistant/helpers/restore_state.py b/homeassistant/helpers/restore_state.py index 79d46f8ec2e..b8262d3a533 100644 --- a/homeassistant/helpers/restore_state.py +++ b/homeassistant/helpers/restore_state.py @@ -258,7 +258,7 @@ def _encode(value: Any) -> Any: """Little helper to JSON encode a value.""" try: return JSONEncoder.default( - None, # type: ignore + None, # type: ignore[arg-type] value, ) except TypeError: diff --git a/homeassistant/helpers/service.py b/homeassistant/helpers/service.py index 3cf11453e20..e638288a58c 100644 --- a/homeassistant/helpers/service.py +++ b/homeassistant/helpers/service.py @@ -485,7 +485,7 @@ async def async_get_all_descriptions( # Cache missing descriptions if description is None: domain_yaml = loaded[domain] - yaml_description = domain_yaml.get(service, {}) # type: ignore + yaml_description = domain_yaml.get(service, {}) # type: ignore[union-attr] # Don't warn for missing services, because it triggers false # positives for things like scripts, that register as a service @@ -696,7 +696,7 @@ async def _handle_entity_call( entity.async_set_context(context) if isinstance(func, str): - result = hass.async_run_job(partial(getattr(entity, func), **data)) # type: ignore + result = hass.async_run_job(partial(getattr(entity, func), **data)) # type: ignore[arg-type] else: result = hass.async_run_job(func, entity, data) diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index d371017a475..2b93b69fe37 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -836,7 +836,7 @@ def _state_generator(hass: HomeAssistant, domain: str | None) -> Generator: def _get_state_if_valid(hass: HomeAssistant, entity_id: str) -> TemplateState | None: state = hass.states.get(entity_id) if state is None and not valid_entity_id(entity_id): - raise TemplateError(f"Invalid entity ID '{entity_id}'") # type: ignore + raise TemplateError(f"Invalid entity ID '{entity_id}'") # type: ignore[arg-type] return _get_template_state_from_state(hass, entity_id, state)