refactor: Switch annotation away from dataclass

To ease employing getters and setters, we switch the dataclass
to a normal python undecorated class.
This commit is contained in:
Marty Oehme 2024-01-24 11:13:49 +01:00
parent f4a26292a0
commit 67bfc30396
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A
2 changed files with 25 additions and 14 deletions

View file

@ -29,18 +29,25 @@ class Annotation:
Contains all information necessary for the annotation itself, content and metadata.
"""
file: str
color: tuple[float, float, float]
content: str = ""
note: str = ""
page: int = 0
tag: str = ""
type: str = "Highlight"
minimum_similarity_color: float = 1.0
def __post_init__(self):
self._color = self.color or field(default_factory=lambda: (0.0, 0.0, 0.0))
self.tag = self.tag or self._tag_from_colorname(self.colorname or "")
def __init__(
self,
file: str,
color: tuple[float, float, float] = (0.0, 0.0, 0.0),
content: str = "",
note: str = "",
page: int = 0,
tag: str = "",
type: str = "Highlight",
minimum_similarity_color: float = 1.0,
) -> None:
self.minimum_similarity_color = minimum_similarity_color
self.file = file
self.color = color
self.content = content
self.note = note
self.page = page
self.tag = tag
self.type = type
def format(self, formatting: str, doc: Document = Document()):
"""Return a formatted string of the annotation.
@ -89,7 +96,11 @@ class Annotation:
nearest = name
return nearest
def _color_similarity_ratio(self, color_one, color_two):
def _color_similarity_ratio(
self,
color_one: tuple[float, float, float],
color_two: tuple[float, float, float],
) -> float:
"""Return the similarity of two colors between 0 and 1.
Takes two rgb color tuples made of floats between 0 and 1,

2
poetry.lock generated
View file

@ -1084,4 +1084,4 @@ whoosh = ["whoosh"]
[metadata]
lock-version = "2.0"
python-versions = "^3.11"
content-hash = "02d5ac314a19f14103372c7ceccdaec080df3fdc2fdb1381f2f6343cd6d17db4"
content-hash = "273c651cac44163ca183313ce3c7384577f090fd98fa6d28e6a3496cb28254ac"