From d3c6f6132dbf035bbff88afeac517e7d1103e557 Mon Sep 17 00:00:00 2001 From: Andrea Ponti Date: Tue, 8 Apr 2025 15:33:16 +0200 Subject: [PATCH 1/2] Add eq and hash to marks --- parse_document_model/marks.py | 44 ++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/parse_document_model/marks.py b/parse_document_model/marks.py index 1662c56..bca6a65 100644 --- a/parse_document_model/marks.py +++ b/parse_document_model/marks.py @@ -10,15 +10,34 @@ class Color(BaseModel): g: int b: int + def __eq__(self, other: Any) -> bool: + return (isinstance(other, Color) and + self.id == other.id and + self.r == other.r and + self.g == other.g and + self.b == other.b) + + def __hash__(self) -> int: + return hash((self.id, self.r, self.g, self.b)) + class Font(BaseModel): id: str name: str size: int + def __eq__(self, other: Any) -> bool: + return (isinstance(other, Font) and + self.id == other.id and + self.size == other.size and + self.name == other.name) + + def __hash__(self) -> int: + return hash((self.id, self.size, self.name)) + class Mark(BaseModel): - category: Literal['bold', 'italic', 'textStyle', 'link'] + category: Literal['bold', 'italic', 'superscripted', 'serifed', 'monospaced', 'textStyle', 'link'] @model_validator(mode='before') def check_details(self: Any) -> Any: @@ -37,11 +56,34 @@ def check_details(self: Any) -> Any: raise ValueError('textStyle should not be provided when type is link') return self + def __eq__(self, other): + return isinstance(other, Mark) and self.category == other.category + + def __hash__(self) -> int: + return hash(self.category) + class TextStyleMark(Mark): color: Optional[Color] = None font: Optional[Font] = None + def __eq__(self, other): + return (isinstance(other, TextStyleMark) and + self.category == other.category and + self.color == other.color and + self.font == other.font) + + def __hash__(self) -> int: + return hash((self.category, self.color, self.font)) + class UrlMark(Mark): url: str + + def __eq__(self, other): + return (isinstance(other, UrlMark) and + self.category == other.category and + self.url == other.url) + + def __hash__(self) -> int: + return hash((self.category, self.url)) From 1509309bac8b41921ff203a4cfd77f979242b11d Mon Sep 17 00:00:00 2001 From: Andrea Ponti Date: Tue, 8 Apr 2025 15:33:33 +0200 Subject: [PATCH 2/2] Bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index f08d241..870e17a 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name='parse-document-model', - version='0.2.1', + version='0.2.2', description='Pydantic models for representing a text document as a hierarchical structure.', long_description=long_description, long_description_content_type='text/markdown',