From 265f58776890f8851dc20b83768c360f88d319a6 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 8 Jan 2024 09:58:07 +0100 Subject: [PATCH] Enable strict typing for history_stats (#107273) --- .strict-typing | 1 + homeassistant/components/history_stats/sensor.py | 5 ++++- mypy.ini | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.strict-typing b/.strict-typing index df1e50b5f6d..8aa14e5b40d 100644 --- a/.strict-typing +++ b/.strict-typing @@ -193,6 +193,7 @@ homeassistant.components.hardkernel.* homeassistant.components.hardware.* homeassistant.components.here_travel_time.* homeassistant.components.history.* +homeassistant.components.history_stats.* homeassistant.components.holiday.* homeassistant.components.homeassistant.exposed_entities homeassistant.components.homeassistant.triggers.event diff --git a/homeassistant/components/history_stats/sensor.py b/homeassistant/components/history_stats/sensor.py index baa39468bc1..7f318b03e06 100644 --- a/homeassistant/components/history_stats/sensor.py +++ b/homeassistant/components/history_stats/sensor.py @@ -3,6 +3,7 @@ from __future__ import annotations from abc import abstractmethod import datetime +from typing import Any, TypeVar import voluptuous as vol @@ -53,8 +54,10 @@ UNITS: dict[str, str] = { } ICON = "mdi:chart-line" +_T = TypeVar("_T", bound=dict[str, Any]) -def exactly_two_period_keys(conf): + +def exactly_two_period_keys(conf: _T) -> _T: """Ensure exactly 2 of CONF_PERIOD_KEYS are provided.""" if sum(param in conf for param in CONF_PERIOD_KEYS) != 2: raise vol.Invalid( diff --git a/mypy.ini b/mypy.ini index 26bb35d9695..f1bf9abbb9d 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1691,6 +1691,16 @@ disallow_untyped_defs = true warn_return_any = true warn_unreachable = true +[mypy-homeassistant.components.history_stats.*] +check_untyped_defs = true +disallow_incomplete_defs = true +disallow_subclassing_any = true +disallow_untyped_calls = true +disallow_untyped_decorators = true +disallow_untyped_defs = true +warn_return_any = true +warn_unreachable = true + [mypy-homeassistant.components.holiday.*] check_untyped_defs = true disallow_incomplete_defs = true