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 collections.abc import Callable
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, cast
|
from typing import Any, TypeVar, cast
|
||||||
|
|
||||||
import ciso8601
|
import ciso8601
|
||||||
from fnvhash import fnv1a_32
|
from fnvhash import fnv1a_32
|
||||||
|
@ -55,6 +55,8 @@ Base = declarative_base()
|
||||||
|
|
||||||
SCHEMA_VERSION = 29
|
SCHEMA_VERSION = 29
|
||||||
|
|
||||||
|
_StatisticsBaseSelfT = TypeVar("_StatisticsBaseSelfT", bound="StatisticsBase")
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
TABLE_EVENTS = "events"
|
TABLE_EVENTS = "events"
|
||||||
|
@ -443,7 +445,9 @@ class StatisticsBase:
|
||||||
sum = Column(DOUBLE_TYPE)
|
sum = Column(DOUBLE_TYPE)
|
||||||
|
|
||||||
@classmethod
|
@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."""
|
"""Create object from a statistics."""
|
||||||
return cls( # type: ignore[call-arg,misc]
|
return cls( # type: ignore[call-arg,misc]
|
||||||
metadata_id=metadata_id,
|
metadata_id=metadata_id,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue