From 65aaabb0c7039ccf07fab3d25df08c0c8b0fbae2 Mon Sep 17 00:00:00 2001 From: rdbende Date: Mon, 11 Dec 2023 21:21:28 +0100 Subject: [PATCH] Update type annotations in random places --- cozy/model/settings.py | 11 +++++------ cozy/view_model/book_detail_view_model.py | 16 +++++++--------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/cozy/model/settings.py b/cozy/model/settings.py index f08f2ec6..34501162 100644 --- a/cozy/model/settings.py +++ b/cozy/model/settings.py @@ -1,5 +1,4 @@ import logging -from typing import List, Optional import peewee @@ -16,8 +15,8 @@ class Settings: - _storages: List[Storage] = [] - _db = cache = inject.attr(SqliteDatabase) + _storages: list[Storage] = [] + _db = inject.attr(SqliteDatabase) def __init__(self): self._db_object: SettingsModel = SettingsModel.get() @@ -27,7 +26,7 @@ def first_start(self) -> bool: return self._db_object.first_start @property - def last_played_book(self) -> Optional[Book]: + def last_played_book(self) -> Book | None: try: return self._db_object.last_played_book except peewee.DoesNotExist: @@ -54,14 +53,14 @@ def default_location(self) -> bool: return True @property - def storage_locations(self): + def storage_locations(self) -> list[Storage]: if not self._storages: self._load_all_storage_locations() return self._storages @property - def external_storage_locations(self): + def external_storage_locations(self) -> list[Storage]: if not self._storages: self._load_all_storage_locations() diff --git a/cozy/view_model/book_detail_view_model.py b/cozy/view_model/book_detail_view_model.py index 04d7f8f8..e3d2973a 100644 --- a/cozy/view_model/book_detail_view_model.py +++ b/cozy/view_model/book_detail_view_model.py @@ -1,5 +1,3 @@ -from typing import Optional - from cozy import tools from cozy.application_settings import ApplicationSettings from cozy.architecture.event_sender import EventSender @@ -29,7 +27,7 @@ def __init__(self): self._play = False self._current_chapter = None - self._book: Book = None + self._book: Book | None = None self._lock_ui: bool = False self._player.add_listener(self._on_player_event) @@ -45,14 +43,14 @@ def playing(self) -> bool: return self._player.playing @property - def current_chapter(self) -> Optional[Chapter]: + def current_chapter(self) -> Chapter | None: if not self.book: return None return self.book.current_chapter @property - def book(self) -> Optional[Book]: + def book(self) -> Book | None: return self._book @book.setter @@ -77,21 +75,21 @@ def book(self, value: Book): self._notify("book") @property - def last_played_text(self) -> Optional[str]: + def last_played_text(self) -> str | None: if not self._book: return None return tools.past_date_to_human_readable(self._book.last_played) @property - def total_text(self) -> Optional[str]: + def total_text(self) -> str | None: if not self._book: return None return tools.seconds_to_human_readable(self._book.duration / self._book.playback_speed) @property - def remaining_text(self) -> Optional[str]: + def remaining_text(self) -> str | None: if not self._book: return None @@ -99,7 +97,7 @@ def remaining_text(self) -> Optional[str]: return tools.seconds_to_human_readable(remaining / self._book.playback_speed) @property - def progress_percent(self) -> Optional[float]: + def progress_percent(self) -> float | None: if not self._book: return None elif self._book.duration < 1: