From 5ffc34d4a29f0224c244cefc82da88679d982b02 Mon Sep 17 00:00:00 2001 From: Markus Bilz Date: Mon, 8 Jan 2024 10:58:02 +0100 Subject: [PATCH] =?UTF-8?q?refactor:=20run=20mypy=20checks=20=F0=9F=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 7 +++++++ mypy.ini | 2 ++ utils/main.py | 30 ++++++++++++++++++++++-------- 3 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 mypy.ini diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 88fb5be..c6b876e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,6 +14,13 @@ repos: - id: debug-statements - id: end-of-file-fixer - id: mixed-line-ending + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.8.0 + hooks: + - id: mypy + # yaml requires additional stubs. + # Similar to: https://stackoverflow.com/a/73603491/5755604 + additional_dependencies: ['types-PyYAML'] - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.1.11 hooks: diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 0000000..0ee646e --- /dev/null +++ b/mypy.ini @@ -0,0 +1,2 @@ +[mypy] +exclude = "utils/ccl_chrome_indexeddb/*.py" diff --git a/utils/main.py b/utils/main.py index 440b173..10085db 100644 --- a/utils/main.py +++ b/utils/main.py @@ -8,13 +8,23 @@ import click from bs4 import BeautifulSoup from consts import XTRACT_HEADER -from dataclasses_json import LetterCase, Undefined, config, dataclass_json +from dataclasses_json import ( + DataClassJsonMixin, + LetterCase, + Undefined, + config, +) from shared import parse_db, write_results_to_json +CAMEL_CASE_CONFIG = config(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE)[ + "dataclasses_json" +] + -@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE) @dataclass() -class Meeting: +class Meeting(DataClassJsonMixin): + dataclass_json_config = CAMEL_CASE_CONFIG + client_update_time: Optional[str] = None cached_deduplication_key: Optional[str] = None id: Optional[str] = None @@ -37,9 +47,10 @@ def __lt__(self, other): return self.cached_deduplication_key < other.cached_deduplication_key -@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE) @dataclass() -class Message: +class Message(DataClassJsonMixin): + dataclass_json_config = CAMEL_CASE_CONFIG + attachments: list[Any] = field(default_factory=list) cached_deduplication_key: Optional[str] = None client_arrival_time: Optional[str] = None @@ -66,7 +77,9 @@ class Message: def __post_init__(self): if self.cached_deduplication_key is None: - self.cached_deduplication_key = self.creator + self.clientmessageid + self.cached_deduplication_key = str(self.creator) + str( + self.clientmessageid + ) def __eq__(self, other): return ( @@ -81,9 +94,10 @@ def __lt__(self, other): return self.cached_deduplication_key < other.cached_deduplication_key -@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE) @dataclass() -class Contact: +class Contact(DataClassJsonMixin): + dataclass_json_config = CAMEL_CASE_CONFIG + display_name: Optional[str] = None email: Optional[str] = None mri: Optional[str] = field(default=None, compare=True)