Using some new python 3.10 features.
Signed-off-by: Cliff Hill <xlorep@darkhelm.org>
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
"""Contains the data models used throughout the application."""
|
||||
import dataclasses
|
||||
import datetime
|
||||
import typing
|
||||
|
||||
import sqlalchemy.orm # type: ignore [import]
|
||||
|
||||
@@ -57,11 +56,11 @@ class Track(base.BaseData):
|
||||
play_count: int = dataclasses.field(
|
||||
metadata={"sa": sqlalchemy.Column(sqlalchemy.Integer, nullable=False)},
|
||||
)
|
||||
rating: typing.Optional[int] = dataclasses.field(
|
||||
rating: int | None = dataclasses.field(
|
||||
default=None,
|
||||
metadata={"sa": sqlalchemy.Column(sqlalchemy.Integer)},
|
||||
)
|
||||
played: typing.Optional[datetime.datetime] = dataclasses.field(
|
||||
played: datetime.datetime | None = dataclasses.field(
|
||||
default=None,
|
||||
metadata={"sa": sqlalchemy.Column(sqlalchemy.DateTime)},
|
||||
)
|
||||
|
||||
@@ -56,7 +56,7 @@ def calc_duration(durations: list[int]) -> None:
|
||||
async def gen_tracks(
|
||||
*,
|
||||
batch_size: int = settings.get().download.batch_size,
|
||||
) -> typing.AsyncGenerator[models.Track, None]:
|
||||
) -> collections.abc.AsyncGenerator[models.Track, None]:
|
||||
"""Generate all Tracks from the Server, asynchronously.
|
||||
|
||||
Args:
|
||||
|
||||
@@ -4,11 +4,10 @@ from __future__ import annotations
|
||||
import collections.abc
|
||||
import contextlib
|
||||
import datetime
|
||||
import typing
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def time_this() -> typing.Generator[None, None, None]: # pragma: no cover
|
||||
def time_this() -> collections.abc.Generator[None, None, None]: # pragma: no cover
|
||||
"""Context manager to time the execution of a block of code."""
|
||||
start = datetime.datetime.now()
|
||||
try:
|
||||
@@ -21,7 +20,7 @@ def time_this() -> typing.Generator[None, None, None]: # pragma: no cover
|
||||
def harmonic_mean(
|
||||
data: collections.abc.Sequence[float],
|
||||
*,
|
||||
weights: typing.Optional[collections.abc.Sequence[float]] = None,
|
||||
weights: collections.abc.Sequence[float] | None = None,
|
||||
) -> float:
|
||||
"""Calculate the [weighted] harmonic mean of the given data.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user