From 1a1eeb2274903cb18f4fb99a4ea3af94f4a04059 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Wed, 20 Jul 2022 04:02:03 +0200 Subject: [PATCH] Allow for subclass typing with StatisticsBase (#75476) --- homeassistant/components/recorder/db_schema.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/recorder/db_schema.py b/homeassistant/components/recorder/db_schema.py index 36487353e25..4777eeb500e 100644 --- a/homeassistant/components/recorder/db_schema.py +++ b/homeassistant/components/recorder/db_schema.py @@ -4,7 +4,7 @@ from __future__ import annotations from collections.abc import Callable from datetime import datetime, timedelta import logging -from typing import Any, cast +from typing import Any, TypeVar, cast import ciso8601 from fnvhash import fnv1a_32 @@ -55,6 +55,8 @@ Base = declarative_base() SCHEMA_VERSION = 29 +_StatisticsBaseSelfT = TypeVar("_StatisticsBaseSelfT", bound="StatisticsBase") + _LOGGER = logging.getLogger(__name__) TABLE_EVENTS = "events" @@ -443,7 +445,9 @@ class StatisticsBase: sum = Column(DOUBLE_TYPE) @classmethod - def from_stats(cls, metadata_id: int, stats: StatisticData) -> StatisticsBase: + def from_stats( + cls: type[_StatisticsBaseSelfT], metadata_id: int, stats: StatisticData + ) -> _StatisticsBaseSelfT: """Create object from a statistics.""" return cls( # type: ignore[call-arg,misc] metadata_id=metadata_id,