Allow for subclass typing with StatisticsBase (#75476)
This commit is contained in:
parent
3193ea3359
commit
1a1eeb2274
1 changed files with 6 additions and 2 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue