From 76edb0bcc008b9bb787aaa2be663a0016fab09f2 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Sun, 5 Apr 2020 12:27:43 -0600 Subject: [PATCH] Fixed some mypy errors --- sublime/app.py | 9 +++++++++ sublime/ui/util.py | 12 ++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/sublime/app.py b/sublime/app.py index f3cc8ff..2799d93 100644 --- a/sublime/app.py +++ b/sublime/app.py @@ -253,6 +253,11 @@ class SublimeMusicApp(Gtk.Application): return offset_seconds = offset / second_microsecond_conversion new_seconds = self.state.song_progress + offset_seconds + + # This should not ever happen. The current_song should always have + # a duration, but the Child object has `duration` optional because + # it could be a directory. + assert self.state.current_song.duration is not None self.on_song_scrub( None, new_seconds / self.state.current_song.duration * 100) @@ -713,6 +718,10 @@ class SublimeMusicApp(Gtk.Application): if not self.state.current_song or not self.window: return + # This should not ever happen. The current_song should always have + # a duration, but the Child object has `duration` optional because + # it could be a directory. + assert self.state.current_song.duration is not None new_time = self.state.current_song.duration * (scrub_value / 100) self.state.song_progress = new_time diff --git a/sublime/ui/util.py b/sublime/ui/util.py index 28cf8d4..9893a90 100644 --- a/sublime/ui/util.py +++ b/sublime/ui/util.py @@ -1,7 +1,8 @@ import functools import re from concurrent.futures import Future -from typing import Any, Callable, cast, Iterable, List, Match, Tuple, Union +from typing import ( + Any, Callable, cast, Iterable, List, Match, Optional, Tuple, Union) import gi from deepdiff import DeepDiff @@ -13,7 +14,7 @@ from sublime.server.api_objects import Playlist from sublime.state_manager import ApplicationState -def format_song_duration(duration_secs: int) -> str: +def format_song_duration(duration_secs: Optional[int]) -> str: """ Formats the song duration as mins:seconds with the seconds being zero-padded if necessary. @@ -23,6 +24,9 @@ def format_song_duration(duration_secs: int) -> str: >>> format_song_duration(62) '1:02' """ + if not duration_secs: + return '-:--' + return f'{duration_secs // 60}:{duration_secs % 60:02}' @@ -80,9 +84,9 @@ def format_sequence_duration(duration_secs: int) -> str: return ', '.join(format_components) -def esc(string: str) -> str: +def esc(string: Optional[str]) -> str: if string is None: - return None + return '' return string.replace('&', '&').replace(" target='_blank'", '')