From 90de25601c3e3a8ba593b20d05963b3437f50b29 Mon Sep 17 00:00:00 2001 From: Ren Tatsumoto Date: Sat, 31 Aug 2024 03:37:37 +0300 Subject: [PATCH] fix mypy complaining --- cropro/widgets/note_previewer.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/cropro/widgets/note_previewer.py b/cropro/widgets/note_previewer.py index 061a78b..3242baa 100644 --- a/cropro/widgets/note_previewer.py +++ b/cropro/widgets/note_previewer.py @@ -128,12 +128,6 @@ def load_note(self, note: Union[Note, RemoteNote]) -> None: ) self.show() - def _is_remote_note(self) -> bool: - return isinstance(self._note, RemoteNote) - - def _is_local_note(self) -> bool: - return isinstance(self._note, Note) - def _generate_html_for_note(self, note: Union[Note, RemoteNote]) -> str: """Creates html for the previewer showing the current note.""" markup = io.StringIO() @@ -142,10 +136,12 @@ def _generate_html_for_note(self, note: Union[Note, RemoteNote]) -> str: continue markup.write(f'
{field_name}
') markup.write('
') - if self._is_remote_note(): + if isinstance(self._note, RemoteNote): markup.write(self._create_html_for_remote_field(field_name, field_content)) - else: + elif isinstance(self._note, Note): markup.write(self._create_html_for_field(field_content)) + else: + raise ValueError(f"Unknown type {type(self._note)}") markup.write("
") if note.tags: markup.write('
Tags
') @@ -154,7 +150,7 @@ def _generate_html_for_note(self, note: Union[Note, RemoteNote]) -> str: def _create_html_for_remote_field(self, field_name: str, field_content: str) -> str: """Creates the content for the previewer showing the remote note's field.""" - assert self._is_remote_note(), "Remote note required." + assert isinstance(self._note, RemoteNote), "Remote note required." markup = io.StringIO() if field_name == self._note.image.field_name: markup.write(format_remote_image(self._note.image)) @@ -166,7 +162,7 @@ def _create_html_for_remote_field(self, field_name: str, field_content: str) -> def _create_html_for_field(self, field_content: str) -> str: """Creates the content for the previewer showing the local note's field.""" - assert self._is_local_note(), "Local note required." + assert isinstance(self._note, Note), "Local note required." markup = io.StringIO() if audio_files := find_sounds(field_content): markup.write(f'
{format_local_audio(audio_files)}
') @@ -181,7 +177,7 @@ def _handle_play_button_press(self, cmd: str): from aqt import sound if cmd.startswith("cropro__play_file:"): - assert self._is_local_note(), "Only local files can be played with av_player." + assert isinstance(self._note, Note), "Only local files can be played with av_player." file_name = os.path.basename(urllib.parse.unquote(cmd.split(":", maxsplit=1)[-1])) file_path = os.path.join(self._note.col.media.dir(), file_name) return sound.av_player.play_tags(