Add type ignore error codes [helpers] (#66776)
This commit is contained in:
parent
0188e8b319
commit
bfb1abd3a2
12 changed files with 25 additions and 23 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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, ...]
|
||||
|
|
|
@ -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"],
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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."""
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue