Fixed the rest of the flake8 errors
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Pattern
|
||||
|
||||
from termcolor import cprint
|
||||
|
||||
@@ -10,7 +11,7 @@ todo_re = re.compile(r"\s*#\s*TODO:?\s*")
|
||||
accounted_for_todo = re.compile(r"\s*#\s*TODO:?\s*\((#\d+)\)")
|
||||
|
||||
|
||||
def noqa_re(error_id: str = ""):
|
||||
def noqa_re(error_id: str = "") -> Pattern:
|
||||
return re.compile(rf"#\s*noqa(:\s*{error_id})?\s*\n$")
|
||||
|
||||
|
||||
|
@@ -16,9 +16,9 @@ from typing import (
|
||||
|
||||
from .api_objects import (
|
||||
Genre,
|
||||
Song,
|
||||
Playlist,
|
||||
PlaylistDetails,
|
||||
Song,
|
||||
)
|
||||
|
||||
|
||||
@@ -355,7 +355,7 @@ class Adapter(abc.ABC):
|
||||
"""
|
||||
raise self._check_can_error("get_cover_art_uri")
|
||||
|
||||
def get_song_uri(self, song_id: str, scheme: str, stream=False) -> str:
|
||||
def get_song_uri(self, song_id: str, scheme: str, stream: bool = False) -> str:
|
||||
"""
|
||||
Get a URI for a given song.
|
||||
|
||||
|
@@ -21,6 +21,7 @@ class Genre(abc.ABC):
|
||||
|
||||
|
||||
class Song(abc.ABC):
|
||||
# TODO make these cross-reference the corresponding Album / Artist / Directory
|
||||
id: str
|
||||
title: str
|
||||
parent: str
|
||||
|
@@ -140,7 +140,7 @@ class FilesystemAdapter(CachingAdapter):
|
||||
|
||||
return str(cover_art_filename)
|
||||
|
||||
def get_song_uri(self, song_id: str, scheme: str, stream=False) -> str:
|
||||
def get_song_uri(self, song_id: str, scheme: str, stream: bool = False) -> str:
|
||||
song = models.Song.get_or_none(models.Song.id == song_id)
|
||||
if not song:
|
||||
if self.is_cache:
|
||||
@@ -250,7 +250,7 @@ class FilesystemAdapter(CachingAdapter):
|
||||
last_ingestion_time=datetime.now(),
|
||||
).on_conflict_replace().execute()
|
||||
|
||||
def ingest_song_data(song_data: Dict[str, Any]):
|
||||
def ingest_song_data(song_data: Dict[str, Any]) -> models.Song:
|
||||
song, created = models.Song.get_or_create(
|
||||
id=song_data["id"], defaults=song_data
|
||||
)
|
||||
@@ -349,7 +349,7 @@ class FilesystemAdapter(CachingAdapter):
|
||||
models.CacheInfo.params_hash == util.params_hash(*params),
|
||||
).execute()
|
||||
|
||||
def delete_cover_art(cover_art_id):
|
||||
def delete_cover_art(cover_art_id: str):
|
||||
cover_art_params_hash = util.params_hash(cover_art_id)
|
||||
if cover_art_file := self.cover_art_dir.joinpath(cover_art_params_hash):
|
||||
cover_art_file.unlink(missing_ok=True)
|
||||
|
@@ -74,6 +74,7 @@ class Song(BaseModel):
|
||||
album_id = TextField(null=True)
|
||||
artist = TextField(null=True)
|
||||
artist_id = TextField(null=True)
|
||||
|
||||
parent = TextField(null=True)
|
||||
|
||||
_genre = ForeignKeyField(Genre, null=True)
|
||||
@@ -83,7 +84,7 @@ class Song(BaseModel):
|
||||
return self._genre.name if self._genre else None
|
||||
|
||||
@genre.setter
|
||||
def genre(self, genre_name):
|
||||
def genre(self, genre_name: str):
|
||||
if not genre_name:
|
||||
return
|
||||
genre, genre_created = Genre.get_or_create(
|
||||
|
@@ -49,7 +49,7 @@ class Result(Generic[T]):
|
||||
self,
|
||||
data_resolver: Union[T, Callable[[], T]],
|
||||
*args,
|
||||
is_download=False,
|
||||
is_download: bool = False,
|
||||
default_value: T = None,
|
||||
):
|
||||
"""
|
||||
@@ -218,7 +218,7 @@ class AdapterManager:
|
||||
TAdapter = TypeVar("TAdapter", bound=Adapter)
|
||||
|
||||
@staticmethod
|
||||
def _adapter_can_do(adapter: Optional[TAdapter], action_name: str):
|
||||
def _adapter_can_do(adapter: Optional[TAdapter], action_name: str) -> bool:
|
||||
return (
|
||||
adapter is not None
|
||||
and adapter.can_service_requests
|
||||
@@ -226,13 +226,13 @@ class AdapterManager:
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _cache_can_do(action_name: str):
|
||||
def _cache_can_do(action_name: str) -> bool:
|
||||
return AdapterManager._instance is not None and AdapterManager._adapter_can_do(
|
||||
AdapterManager._instance.caching_adapter, action_name
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _ground_truth_can_do(action_name: str):
|
||||
def _ground_truth_can_do(action_name: str) -> bool:
|
||||
return AdapterManager._instance is not None and AdapterManager._adapter_can_do(
|
||||
AdapterManager._instance.ground_truth_adapter, action_name
|
||||
)
|
||||
@@ -244,7 +244,7 @@ class AdapterManager:
|
||||
return AdapterManager._cache_can_do(action_name)
|
||||
|
||||
@staticmethod
|
||||
def _any_adapter_can_do(action_name: str):
|
||||
def _any_adapter_can_do(action_name: str) -> bool:
|
||||
if AdapterManager._instance is None:
|
||||
return False
|
||||
|
||||
@@ -332,7 +332,8 @@ class AdapterManager:
|
||||
return future_finished
|
||||
|
||||
@staticmethod
|
||||
def _get_scheme():
|
||||
def _get_scheme() -> str:
|
||||
assert AdapterManager._instance
|
||||
scheme_priority = ("https", "http")
|
||||
schemes = sorted(
|
||||
AdapterManager._instance.ground_truth_adapter.supported_schemes,
|
||||
@@ -398,7 +399,7 @@ class AdapterManager:
|
||||
logging.exception(f'Error on {"get_playlists"} retrieving from cache.')
|
||||
|
||||
if not allow_download:
|
||||
raise CacheMissError(partial_data=partial_playlist_data)
|
||||
raise CacheMissError(partial_data=partial_playlists_data)
|
||||
|
||||
if AdapterManager._instance.caching_adapter and force:
|
||||
AdapterManager._instance.caching_adapter.invalidate_data(
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import json
|
||||
import logging
|
||||
import multiprocessing
|
||||
import os
|
||||
import random
|
||||
import multiprocessing
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from time import sleep
|
||||
@@ -284,7 +284,7 @@ class SubsonicAdapter(Adapter):
|
||||
params = {"id": cover_art_id, "size": 2000, **self._get_params()}
|
||||
return self._make_url("getCoverArt") + "?" + urlencode(params)
|
||||
|
||||
def get_song_uri(self, song_id: str, scheme: str, stream=False) -> str:
|
||||
def get_song_uri(self, song_id: str, scheme: str, stream: bool = False) -> str:
|
||||
params = {"id": song_id, **self._get_params()}
|
||||
endpoint = "stream" if stream else "download"
|
||||
return self._make_url(endpoint) + "?" + urlencode(params)
|
||||
|
@@ -598,7 +598,8 @@ class SublimeMusicApp(Gtk.Application):
|
||||
self.update_window()
|
||||
|
||||
@dbus_propagate()
|
||||
def on_play_next(self, action: Any, song_ids: Tuple[str, ...]):
|
||||
def on_play_next(self, action: Any, song_ids: GLib.Variant):
|
||||
song_ids = tuple(song_ids)
|
||||
if self.app_config.state.current_song is None:
|
||||
insert_at = 0
|
||||
else:
|
||||
@@ -614,8 +615,7 @@ class SublimeMusicApp(Gtk.Application):
|
||||
|
||||
@dbus_propagate()
|
||||
def on_add_to_queue(self, action: Any, song_ids: GLib.Variant):
|
||||
print(song_ids)
|
||||
print(type(song_ids))
|
||||
song_ids = tuple(song_ids)
|
||||
self.app_config.state.play_queue += tuple(song_ids)
|
||||
self.app_config.state.old_play_queue += tuple(song_ids)
|
||||
self.update_window()
|
||||
@@ -719,7 +719,6 @@ class SublimeMusicApp(Gtk.Application):
|
||||
song_queue: Tuple[str, ...],
|
||||
metadata: Dict[str, Any],
|
||||
):
|
||||
print(type(song_queue), song_queue)
|
||||
song_queue = tuple(song_queue)
|
||||
# Reset the play queue so that we don't ever revert back to the
|
||||
# previous one.
|
||||
@@ -1114,8 +1113,8 @@ class SublimeMusicApp(Gtk.Application):
|
||||
play_queue_len: int = len(self.app_config.state.play_queue)
|
||||
if is_repeat_queue or prefetch_idx < play_queue_len:
|
||||
prefetch_idxs.append(
|
||||
prefetch_idx % play_queue_len
|
||||
) # noqa: S001
|
||||
prefetch_idx % play_queue_len # noqa: S001
|
||||
)
|
||||
AdapterManager.batch_download_songs(
|
||||
[self.app_config.state.play_queue[i] for i in prefetch_idxs],
|
||||
before_download=lambda: self.update_window(),
|
||||
|
@@ -16,7 +16,6 @@ from typing import (
|
||||
|
||||
import gi
|
||||
from deepdiff import DeepDiff
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gdk, GLib, Gtk
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
from time import sleep
|
||||
|
||||
from sublime.adapters import Result
|
||||
|
||||
|
||||
@@ -11,7 +12,7 @@ def test_result_immediate():
|
||||
def test_result_immediate_callback():
|
||||
callback_called = True
|
||||
|
||||
def check_done_callback(f):
|
||||
def check_done_callback(f: Result):
|
||||
nonlocal callback_called
|
||||
assert f.result() == 42
|
||||
callback_called = True
|
||||
@@ -22,7 +23,7 @@ def test_result_immediate_callback():
|
||||
|
||||
|
||||
def test_result_future():
|
||||
def resolve_later():
|
||||
def resolve_later() -> int:
|
||||
sleep(1)
|
||||
return 42
|
||||
|
||||
@@ -33,13 +34,13 @@ def test_result_future():
|
||||
|
||||
|
||||
def test_result_future_callback():
|
||||
def resolve_later():
|
||||
def resolve_later() -> int:
|
||||
sleep(1)
|
||||
return 42
|
||||
|
||||
check_done = False
|
||||
|
||||
def check_done_callback(f):
|
||||
def check_done_callback(f: Result):
|
||||
nonlocal check_done
|
||||
assert result.data_is_available
|
||||
assert f.result() == 42
|
||||
|
@@ -66,7 +66,7 @@ def mock_data_files_multi_part(
|
||||
aggregate.append(line)
|
||||
|
||||
parts.append("\n".join(aggregate))
|
||||
print(parts)
|
||||
print(parts) # noqa: T001
|
||||
yield file, iter(parts)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user