Allow for subclass typing with StatisticsBase (#75476)

This commit is contained in:
Marc Mueller 2022-07-20 04:02:03 +02:00 committed by GitHub
parent 3193ea3359
commit 1a1eeb2274
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,