Add type ignore error codes [helpers] (#66776)

This commit is contained in:
Marc Mueller 2022-02-18 11:31:37 +01:00 committed by GitHub
parent 0188e8b319
commit bfb1abd3a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 25 additions and 23 deletions

View file

@ -104,9 +104,9 @@ def _async_create_clientsession(
# If a package requires a different user agent, override it by passing a headers # If a package requires a different user agent, override it by passing a headers
# dictionary to the request method. # dictionary to the request method.
# pylint: disable=protected-access # 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: if auto_cleanup_method:
auto_cleanup_method(hass, clientsession) auto_cleanup_method(hass, clientsession)

View file

@ -217,7 +217,7 @@ class AbstractOAuth2FlowHandler(config_entries.ConfigFlow, metaclass=ABCMeta):
) )
self.external_data: Any = None self.external_data: Any = None
self.flow_impl: AbstractOAuth2Implementation = None # type: ignore self.flow_impl: AbstractOAuth2Implementation = None # type: ignore[assignment]
@property @property
@abstractmethod @abstractmethod

View file

@ -15,7 +15,9 @@ import logging
from numbers import Number from numbers import Number
import os import os
import re 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 typing import Any, TypeVar, cast, overload
from urllib.parse import urlparse from urllib.parse import urlparse
from uuid import UUID from uuid import UUID
@ -163,7 +165,7 @@ def boolean(value: Any) -> bool:
return False return False
elif isinstance(value, Number): elif isinstance(value, Number):
# type ignore: https://github.com/python/mypy/issues/3186 # 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}") 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: def time_period_str(value: str) -> timedelta:
"""Validate and transform time offset.""" """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") raise vol.Invalid("Make sure you wrap time values in quotes")
if not isinstance(value, str): if not isinstance(value, str):
raise vol.Invalid(TIME_PERIOD_ERROR.format(value)) 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)): if isinstance(value, (list, dict, template_helper.Template)):
raise vol.Invalid("template value should be a string") 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: try:
template_value.ensure_valid() 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)): if not template_helper.is_template_string(str(value)):
raise vol.Invalid("template value does not contain a dynamic template") 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: try:
template_value.ensure_valid() template_value.ensure_valid()
return template_value return template_value
@ -796,7 +798,7 @@ def _deprecated_or_removed(
"""Check if key is in config and log warning or error.""" """Check if key is in config and log warning or error."""
if key in config: if key in config:
try: 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: except AttributeError:
near = "" near = ""
arguments: tuple[str, ...] arguments: tuple[str, ...]

View file

@ -70,7 +70,7 @@ class FlowManagerIndexView(_BaseFlowManagerView):
try: try:
result = await self._flow_mgr.async_init( result = await self._flow_mgr.async_init(
handler, # type: ignore handler, # type: ignore[arg-type]
context={ context={
"source": config_entries.SOURCE_USER, "source": config_entries.SOURCE_USER,
"show_advanced_options": data["show_advanced_options"], "show_advanced_options": data["show_advanced_options"],

View file

@ -97,7 +97,7 @@ class Debouncer:
async with self._execute_lock: async with self._execute_lock:
# Abort if timer got set while we're waiting for the lock. # Abort if timer got set while we're waiting for the lock.
if self._timer_task: if self._timer_task:
return # type: ignore return # type: ignore[unreachable]
try: try:
task = self.hass.async_run_hass_job(self._job) task = self.hass.async_run_hass_job(self._job)

View file

@ -255,12 +255,12 @@ class Entity(ABC):
# SAFE TO OVERWRITE # SAFE TO OVERWRITE
# The properties and methods here are safe to overwrite when inheriting # The properties and methods here are safe to overwrite when inheriting
# this class. These may be used to customize the behavior of the entity. # 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 # Owning hass instance. Will be set by EntityPlatform
# While not purely typed, it makes typehinting more useful for us # While not purely typed, it makes typehinting more useful for us
# and removes the need for constant None checks or asserts. # 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 # Owning platform instance. Will be set by EntityPlatform
platform: EntityPlatform | None = None platform: EntityPlatform | None = None
@ -770,7 +770,7 @@ class Entity(ABC):
@callback @callback
def add_to_platform_abort(self) -> None: def add_to_platform_abort(self) -> None:
"""Abort adding an entity to a platform.""" """Abort adding an entity to a platform."""
self.hass = None # type: ignore self.hass = None # type: ignore[assignment]
self.platform = None self.platform = None
self.parallel_updates = None self.parallel_updates = None
self._added = False self._added = False

View file

@ -71,7 +71,7 @@ def create_async_httpx_client(
original_aclose = client.aclose 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" client.aclose, "closes the Home Assistant httpx client"
) )

View file

@ -152,7 +152,7 @@ class IntentHandler:
extra=vol.ALLOW_EXTRA, 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: async def async_handle(self, intent_obj: Intent) -> IntentResponse:
"""Handle the intent.""" """Handle the intent."""

View file

@ -68,11 +68,11 @@ def find_coordinates(
# Check if entity_state is a zone # Check if entity_state is a zone
zone_entity = hass.states.get(f"zone.{entity_state.state}") 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( _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 # Check if entity_state is a friendly name of a zone
if (zone_coords := resolve_zone(hass, entity_state.state)) is not None: if (zone_coords := resolve_zone(hass, entity_state.state)) is not None:

View file

@ -258,7 +258,7 @@ def _encode(value: Any) -> Any:
"""Little helper to JSON encode a value.""" """Little helper to JSON encode a value."""
try: try:
return JSONEncoder.default( return JSONEncoder.default(
None, # type: ignore None, # type: ignore[arg-type]
value, value,
) )
except TypeError: except TypeError:

View file

@ -485,7 +485,7 @@ async def async_get_all_descriptions(
# Cache missing descriptions # Cache missing descriptions
if description is None: if description is None:
domain_yaml = loaded[domain] 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 # Don't warn for missing services, because it triggers false
# positives for things like scripts, that register as a service # positives for things like scripts, that register as a service
@ -696,7 +696,7 @@ async def _handle_entity_call(
entity.async_set_context(context) entity.async_set_context(context)
if isinstance(func, str): 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: else:
result = hass.async_run_job(func, entity, data) result = hass.async_run_job(func, entity, data)

View file

@ -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: def _get_state_if_valid(hass: HomeAssistant, entity_id: str) -> TemplateState | None:
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
if state is None and not valid_entity_id(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) return _get_template_state_from_state(hass, entity_id, state)