From a70ec64408b234ea0ffb5d3842893955235e171e Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 11 Nov 2023 23:31:04 +0100 Subject: [PATCH] Update mypy to 1.7.0 (#103800) --- homeassistant/bootstrap.py | 2 +- homeassistant/components/assist_pipeline/select.py | 4 +--- homeassistant/components/bond/__init__.py | 4 ++-- homeassistant/components/diagnostics/util.py | 2 +- homeassistant/components/logbook/queries/all.py | 11 +++-------- homeassistant/components/netgear_lte/__init__.py | 2 +- homeassistant/components/notion/__init__.py | 2 +- homeassistant/components/overkiz/__init__.py | 6 +++++- homeassistant/components/overkiz/coordinator.py | 2 +- homeassistant/components/recorder/statistics.py | 5 +---- .../recorder/table_managers/statistics_meta.py | 5 +---- homeassistant/components/sensor/recorder.py | 14 ++------------ homeassistant/components/tplink_lte/__init__.py | 2 +- homeassistant/helpers/device_registry.py | 11 ++--------- homeassistant/helpers/template.py | 4 ++-- homeassistant/helpers/trigger.py | 2 +- requirements_test.txt | 2 +- 17 files changed, 27 insertions(+), 53 deletions(-) diff --git a/homeassistant/bootstrap.py b/homeassistant/bootstrap.py index 098f970d55f..b9bb638e052 100644 --- a/homeassistant/bootstrap.py +++ b/homeassistant/bootstrap.py @@ -398,7 +398,7 @@ def async_enable_logging( logging.getLogger("httpx").setLevel(logging.WARNING) sys.excepthook = lambda *args: logging.getLogger(None).exception( - "Uncaught exception", exc_info=args # type: ignore[arg-type] + "Uncaught exception", exc_info=args ) threading.excepthook = lambda args: logging.getLogger(None).exception( "Uncaught thread exception", diff --git a/homeassistant/components/assist_pipeline/select.py b/homeassistant/components/assist_pipeline/select.py index 2ae46fcb9ac..83e1bd3ab36 100644 --- a/homeassistant/components/assist_pipeline/select.py +++ b/homeassistant/components/assist_pipeline/select.py @@ -93,9 +93,7 @@ class AssistPipelineSelect(SelectEntity, restore_state.RestoreEntity): if self.registry_entry and (device_id := self.registry_entry.device_id): pipeline_data.pipeline_devices.add(device_id) self.async_on_remove( - lambda: pipeline_data.pipeline_devices.discard( - device_id # type: ignore[arg-type] - ) + lambda: pipeline_data.pipeline_devices.discard(device_id) ) async def async_select_option(self, option: str) -> None: diff --git a/homeassistant/components/bond/__init__.py b/homeassistant/components/bond/__init__.py index 46066d9f55e..b6f402004f6 100644 --- a/homeassistant/components/bond/__init__.py +++ b/homeassistant/components/bond/__init__.py @@ -126,10 +126,10 @@ async def async_remove_config_entry_device( for identifier in device_entry.identifiers: if identifier[0] != DOMAIN or len(identifier) != 3: continue - bond_id: str = identifier[1] + bond_id: str = identifier[1] # type: ignore[unreachable] # Bond still uses the 3 arg tuple before # the identifiers were typed - device_id: str = identifier[2] # type: ignore[misc] + device_id: str = identifier[2] # If device_id is no longer present on # the hub, we allow removal. if hub.bond_id != bond_id or not any( diff --git a/homeassistant/components/diagnostics/util.py b/homeassistant/components/diagnostics/util.py index cbb8831e9b5..47a0eac9a0d 100644 --- a/homeassistant/components/diagnostics/util.py +++ b/homeassistant/components/diagnostics/util.py @@ -12,7 +12,7 @@ _T = TypeVar("_T") @overload -def async_redact_data(data: Mapping, to_redact: Iterable[Any]) -> dict: # type: ignore[misc] +def async_redact_data(data: Mapping, to_redact: Iterable[Any]) -> dict: # type: ignore[overload-overlap] ... diff --git a/homeassistant/components/logbook/queries/all.py b/homeassistant/components/logbook/queries/all.py index c6196687ac2..21f88135a1d 100644 --- a/homeassistant/components/logbook/queries/all.py +++ b/homeassistant/components/logbook/queries/all.py @@ -28,18 +28,13 @@ def all_stmt( ) if context_id_bin is not None: stmt += lambda s: s.where(Events.context_id_bin == context_id_bin).union_all( - _states_query_for_context_id( - start_day, - end_day, - # https://github.com/python/mypy/issues/2608 - context_id_bin, # type:ignore[arg-type] - ), + _states_query_for_context_id(start_day, end_day, context_id_bin), ) elif filters and filters.has_config: stmt = stmt.add_criteria( - lambda q: q.filter(filters.events_entity_filter()).union_all( # type: ignore[union-attr] + lambda q: q.filter(filters.events_entity_filter()).union_all( _states_query_for_all(start_day, end_day).where( - filters.states_metadata_entity_filter() # type: ignore[union-attr] + filters.states_metadata_entity_filter() ) ), track_on=[filters], diff --git a/homeassistant/components/netgear_lte/__init__.py b/homeassistant/components/netgear_lte/__init__.py index ed9ee49a0de..d6ce3cb0994 100644 --- a/homeassistant/components/netgear_lte/__init__.py +++ b/homeassistant/components/netgear_lte/__init__.py @@ -124,7 +124,7 @@ class LTEData: """Shared state.""" websession = attr.ib() - modem_data = attr.ib(init=False, factory=dict) + modem_data: dict[str, ModemData] = attr.ib(init=False, factory=dict) def get_modem_data(self, config): """Get modem_data for the host in config.""" diff --git a/homeassistant/components/notion/__init__.py b/homeassistant/components/notion/__init__.py index b8881fdf56d..036ef6e4f0e 100644 --- a/homeassistant/components/notion/__init__.py +++ b/homeassistant/components/notion/__init__.py @@ -192,7 +192,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: if isinstance(result, BaseException): raise result from None - data.update_data_from_response(result) + data.update_data_from_response(result) # type: ignore[arg-type] return data diff --git a/homeassistant/components/overkiz/__init__.py b/homeassistant/components/overkiz/__init__.py index d3fdda07f74..36713d972b1 100644 --- a/homeassistant/components/overkiz/__init__.py +++ b/homeassistant/components/overkiz/__init__.py @@ -4,6 +4,7 @@ from __future__ import annotations import asyncio from collections import defaultdict from dataclasses import dataclass +from typing import cast from aiohttp import ClientError from pyoverkiz.client import OverkizClient @@ -15,7 +16,7 @@ from pyoverkiz.exceptions import ( NotSuchTokenException, TooManyRequestsException, ) -from pyoverkiz.models import Device, Scenario +from pyoverkiz.models import Device, Scenario, Setup from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform @@ -77,6 +78,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: except MaintenanceException as exception: raise ConfigEntryNotReady("Server is down for maintenance") from exception + setup = cast(Setup, setup) + scenarios = cast(list[Scenario], scenarios) + coordinator = OverkizDataUpdateCoordinator( hass, LOGGER, diff --git a/homeassistant/components/overkiz/coordinator.py b/homeassistant/components/overkiz/coordinator.py index 7c9cab5f181..e5079b3d3b8 100644 --- a/homeassistant/components/overkiz/coordinator.py +++ b/homeassistant/components/overkiz/coordinator.py @@ -43,7 +43,7 @@ class OverkizDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Device]]): name: str, client: OverkizClient, devices: list[Device], - places: Place, + places: Place | None, update_interval: timedelta | None = None, config_entry_id: str, ) -> None: diff --git a/homeassistant/components/recorder/statistics.py b/homeassistant/components/recorder/statistics.py index a6fe7ddb22f..78c475753a2 100644 --- a/homeassistant/components/recorder/statistics.py +++ b/homeassistant/components/recorder/statistics.py @@ -1088,10 +1088,7 @@ def _generate_statistics_during_period_stmt( end_time_ts = end_time.timestamp() stmt += lambda q: q.filter(table.start_ts < end_time_ts) if metadata_ids: - stmt += lambda q: q.filter( - # https://github.com/python/mypy/issues/2608 - table.metadata_id.in_(metadata_ids) # type:ignore[arg-type] - ) + stmt += lambda q: q.filter(table.metadata_id.in_(metadata_ids)) stmt += lambda q: q.order_by(table.metadata_id, table.start_ts) return stmt diff --git a/homeassistant/components/recorder/table_managers/statistics_meta.py b/homeassistant/components/recorder/table_managers/statistics_meta.py index 75af59d7c7a..a484bdf145e 100644 --- a/homeassistant/components/recorder/table_managers/statistics_meta.py +++ b/homeassistant/components/recorder/table_managers/statistics_meta.py @@ -41,10 +41,7 @@ def _generate_get_metadata_stmt( """Generate a statement to fetch metadata.""" stmt = lambda_stmt(lambda: select(*QUERY_STATISTIC_META)) if statistic_ids: - stmt += lambda q: q.where( - # https://github.com/python/mypy/issues/2608 - StatisticsMeta.statistic_id.in_(statistic_ids) # type:ignore[arg-type] - ) + stmt += lambda q: q.where(StatisticsMeta.statistic_id.in_(statistic_ids)) if statistic_source is not None: stmt += lambda q: q.where(StatisticsMeta.source == statistic_source) if statistic_type == "mean": diff --git a/homeassistant/components/sensor/recorder.py b/homeassistant/components/sensor/recorder.py index 3cf1dc975ec..d08a20636ab 100644 --- a/homeassistant/components/sensor/recorder.py +++ b/homeassistant/components/sensor/recorder.py @@ -497,19 +497,9 @@ def compile_statistics( # noqa: C901 # Make calculations stat: StatisticData = {"start": start} if "max" in wanted_statistics[entity_id]: - stat["max"] = max( - *itertools.islice( - zip(*valid_float_states), # type: ignore[typeddict-item] - 1, - ) - ) + stat["max"] = max(*itertools.islice(zip(*valid_float_states), 1)) if "min" in wanted_statistics[entity_id]: - stat["min"] = min( - *itertools.islice( - zip(*valid_float_states), # type: ignore[typeddict-item] - 1, - ) - ) + stat["min"] = min(*itertools.islice(zip(*valid_float_states), 1)) if "mean" in wanted_statistics[entity_id]: stat["mean"] = _time_weighted_average(valid_float_states, start, end) diff --git a/homeassistant/components/tplink_lte/__init__.py b/homeassistant/components/tplink_lte/__init__.py index 52ee5dfd980..378fd0a35d4 100644 --- a/homeassistant/components/tplink_lte/__init__.py +++ b/homeassistant/components/tplink_lte/__init__.py @@ -70,7 +70,7 @@ class LTEData: """Shared state.""" websession = attr.ib() - modem_data = attr.ib(init=False, factory=dict) + modem_data: dict[str, ModemData] = attr.ib(init=False, factory=dict) def get_modem_data(self, config): """Get the requested or the only modem_data value.""" diff --git a/homeassistant/helpers/device_registry.py b/homeassistant/helpers/device_registry.py index 48ebd7b6ebc..9a26821faaf 100644 --- a/homeassistant/helpers/device_registry.py +++ b/homeassistant/helpers/device_registry.py @@ -823,15 +823,8 @@ class DeviceRegistry: for device in data["deleted_devices"]: deleted_devices[device["id"]] = DeletedDeviceEntry( config_entries=set(device["config_entries"]), - # type ignores (if tuple arg was cast): likely https://github.com/python/mypy/issues/8625 - connections={ - tuple(conn) # type: ignore[misc] - for conn in device["connections"] - }, - identifiers={ - tuple(iden) # type: ignore[misc] - for iden in device["identifiers"] - }, + connections={tuple(conn) for conn in device["connections"]}, + identifiers={tuple(iden) for iden in device["identifiers"]}, id=device["id"], orphaned_timestamp=device["orphaned_timestamp"], ) diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index fa165da1772..721ac8bd5be 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -2567,7 +2567,7 @@ class TemplateEnvironment(ImmutableSandboxedEnvironment): self.globals["expand"] = hassfunction(expand) self.filters["expand"] = self.globals["expand"] self.globals["closest"] = hassfunction(closest) - self.filters["closest"] = hassfunction(closest_filter) # type: ignore[arg-type] + self.filters["closest"] = hassfunction(closest_filter) self.globals["distance"] = hassfunction(distance) self.globals["is_hidden_entity"] = hassfunction(is_hidden_entity) self.tests["is_hidden_entity"] = hassfunction( @@ -2608,7 +2608,7 @@ class TemplateEnvironment(ImmutableSandboxedEnvironment): return super().is_safe_attribute(obj, attr, value) @overload - def compile( # type: ignore[misc] + def compile( # type: ignore[overload-overlap] self, source: str | jinja2.nodes.Template, name: str | None = None, diff --git a/homeassistant/helpers/trigger.py b/homeassistant/helpers/trigger.py index c5cfdadabb2..a4391061899 100644 --- a/homeassistant/helpers/trigger.py +++ b/homeassistant/helpers/trigger.py @@ -341,7 +341,7 @@ async def async_initialize_triggers( elif isinstance(result, BaseException): raise result from None elif result is None: - log_cb( + log_cb( # type: ignore[unreachable] logging.ERROR, "Unknown error while setting up trigger (empty result)" ) else: diff --git a/requirements_test.txt b/requirements_test.txt index a13ab170086..bc88a59fc8e 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -11,7 +11,7 @@ astroid==3.0.1 coverage==7.3.2 freezegun==1.2.2 mock-open==1.4.0 -mypy==1.6.1 +mypy==1.7.0 pre-commit==3.5.0 pydantic==1.10.12 pylint==3.0.2