Use basedpyright refactor
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
import dataclasses
|
||||
import datetime
|
||||
import enum
|
||||
from typing import Optional
|
||||
from typing import Self
|
||||
|
||||
from folkugat_web.model.search import NGrams
|
||||
from folkugat_web.model.sessions import Session
|
||||
from folkugat_web.services import ngrams
|
||||
|
||||
from ._base import IndexedList, WithId
|
||||
|
||||
NGrams = dict[int, list[str]]
|
||||
|
||||
|
||||
class ContentType(enum.Enum):
|
||||
PARTITURA = "partitura"
|
||||
@@ -28,7 +28,7 @@ class LinkType(enum.Enum):
|
||||
@dataclasses.dataclass
|
||||
class Link(WithId):
|
||||
content_type: ContentType
|
||||
link_type: Optional[LinkType]
|
||||
link_type: LinkType | None
|
||||
url: str
|
||||
title: str = ""
|
||||
|
||||
@@ -93,7 +93,7 @@ class Lyrics(WithId):
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, d):
|
||||
def from_dict(cls, d) -> Self:
|
||||
return cls(
|
||||
id=d["id"],
|
||||
title=d["title"],
|
||||
@@ -103,7 +103,7 @@ class Lyrics(WithId):
|
||||
|
||||
@dataclasses.dataclass
|
||||
class Tema:
|
||||
id: Optional[int] = None
|
||||
id: int | None = None
|
||||
# Info
|
||||
title: str = ""
|
||||
properties: IndexedList[Property] = dataclasses.field(default_factory=IndexedList)
|
||||
@@ -116,6 +116,8 @@ class Tema:
|
||||
# Other info
|
||||
modification_date: datetime.datetime = dataclasses.field(default_factory=datetime.datetime.now)
|
||||
creation_date: datetime.datetime = dataclasses.field(default_factory=datetime.datetime.now)
|
||||
# Stats
|
||||
played: list[Session] = dataclasses.field(default_factory=list)
|
||||
|
||||
def compute_ngrams(self):
|
||||
self.ngrams = ngrams.get_text_ngrams(self.title, *self.alternatives)
|
||||
@@ -124,5 +126,5 @@ class Tema:
|
||||
self.compute_ngrams()
|
||||
return self
|
||||
|
||||
def score(self) -> Optional[Link]:
|
||||
def score(self) -> Link | None:
|
||||
return next(filter(lambda l: l.content_type is ContentType.PARTITURA and l.url.startswith('/'), self.links), None)
|
||||
|
||||
Reference in New Issue
Block a user