Fixed the rest of the flake8 errors

This commit is contained in:
Sumner Evans
2020-05-10 11:23:00 -06:00
parent 65aafd111d
commit c29caf8356
11 changed files with 31 additions and 28 deletions

View File

@@ -3,6 +3,7 @@
import re import re
import sys import sys
from pathlib import Path from pathlib import Path
from typing import Pattern
from termcolor import cprint 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+)\)") 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$") return re.compile(rf"#\s*noqa(:\s*{error_id})?\s*\n$")

View File

@@ -16,9 +16,9 @@ from typing import (
from .api_objects import ( from .api_objects import (
Genre, Genre,
Song,
Playlist, Playlist,
PlaylistDetails, PlaylistDetails,
Song,
) )
@@ -355,7 +355,7 @@ class Adapter(abc.ABC):
""" """
raise self._check_can_error("get_cover_art_uri") 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. Get a URI for a given song.

View File

@@ -21,6 +21,7 @@ class Genre(abc.ABC):
class Song(abc.ABC): class Song(abc.ABC):
# TODO make these cross-reference the corresponding Album / Artist / Directory
id: str id: str
title: str title: str
parent: str parent: str

View File

@@ -140,7 +140,7 @@ class FilesystemAdapter(CachingAdapter):
return str(cover_art_filename) 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) song = models.Song.get_or_none(models.Song.id == song_id)
if not song: if not song:
if self.is_cache: if self.is_cache:
@@ -250,7 +250,7 @@ class FilesystemAdapter(CachingAdapter):
last_ingestion_time=datetime.now(), last_ingestion_time=datetime.now(),
).on_conflict_replace().execute() ).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( song, created = models.Song.get_or_create(
id=song_data["id"], defaults=song_data id=song_data["id"], defaults=song_data
) )
@@ -349,7 +349,7 @@ class FilesystemAdapter(CachingAdapter):
models.CacheInfo.params_hash == util.params_hash(*params), models.CacheInfo.params_hash == util.params_hash(*params),
).execute() ).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) cover_art_params_hash = util.params_hash(cover_art_id)
if cover_art_file := self.cover_art_dir.joinpath(cover_art_params_hash): if cover_art_file := self.cover_art_dir.joinpath(cover_art_params_hash):
cover_art_file.unlink(missing_ok=True) cover_art_file.unlink(missing_ok=True)

View File

@@ -74,6 +74,7 @@ class Song(BaseModel):
album_id = TextField(null=True) album_id = TextField(null=True)
artist = TextField(null=True) artist = TextField(null=True)
artist_id = TextField(null=True) artist_id = TextField(null=True)
parent = TextField(null=True) parent = TextField(null=True)
_genre = ForeignKeyField(Genre, null=True) _genre = ForeignKeyField(Genre, null=True)
@@ -83,7 +84,7 @@ class Song(BaseModel):
return self._genre.name if self._genre else None return self._genre.name if self._genre else None
@genre.setter @genre.setter
def genre(self, genre_name): def genre(self, genre_name: str):
if not genre_name: if not genre_name:
return return
genre, genre_created = Genre.get_or_create( genre, genre_created = Genre.get_or_create(

View File

@@ -49,7 +49,7 @@ class Result(Generic[T]):
self, self,
data_resolver: Union[T, Callable[[], T]], data_resolver: Union[T, Callable[[], T]],
*args, *args,
is_download=False, is_download: bool = False,
default_value: T = None, default_value: T = None,
): ):
""" """
@@ -218,7 +218,7 @@ class AdapterManager:
TAdapter = TypeVar("TAdapter", bound=Adapter) TAdapter = TypeVar("TAdapter", bound=Adapter)
@staticmethod @staticmethod
def _adapter_can_do(adapter: Optional[TAdapter], action_name: str): def _adapter_can_do(adapter: Optional[TAdapter], action_name: str) -> bool:
return ( return (
adapter is not None adapter is not None
and adapter.can_service_requests and adapter.can_service_requests
@@ -226,13 +226,13 @@ class AdapterManager:
) )
@staticmethod @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( return AdapterManager._instance is not None and AdapterManager._adapter_can_do(
AdapterManager._instance.caching_adapter, action_name AdapterManager._instance.caching_adapter, action_name
) )
@staticmethod @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( return AdapterManager._instance is not None and AdapterManager._adapter_can_do(
AdapterManager._instance.ground_truth_adapter, action_name AdapterManager._instance.ground_truth_adapter, action_name
) )
@@ -244,7 +244,7 @@ class AdapterManager:
return AdapterManager._cache_can_do(action_name) return AdapterManager._cache_can_do(action_name)
@staticmethod @staticmethod
def _any_adapter_can_do(action_name: str): def _any_adapter_can_do(action_name: str) -> bool:
if AdapterManager._instance is None: if AdapterManager._instance is None:
return False return False
@@ -332,7 +332,8 @@ class AdapterManager:
return future_finished return future_finished
@staticmethod @staticmethod
def _get_scheme(): def _get_scheme() -> str:
assert AdapterManager._instance
scheme_priority = ("https", "http") scheme_priority = ("https", "http")
schemes = sorted( schemes = sorted(
AdapterManager._instance.ground_truth_adapter.supported_schemes, AdapterManager._instance.ground_truth_adapter.supported_schemes,
@@ -398,7 +399,7 @@ class AdapterManager:
logging.exception(f'Error on {"get_playlists"} retrieving from cache.') logging.exception(f'Error on {"get_playlists"} retrieving from cache.')
if not allow_download: 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: if AdapterManager._instance.caching_adapter and force:
AdapterManager._instance.caching_adapter.invalidate_data( AdapterManager._instance.caching_adapter.invalidate_data(

View File

@@ -1,8 +1,8 @@
import json import json
import logging import logging
import multiprocessing
import os import os
import random import random
import multiprocessing
from datetime import datetime from datetime import datetime
from pathlib import Path from pathlib import Path
from time import sleep from time import sleep
@@ -284,7 +284,7 @@ class SubsonicAdapter(Adapter):
params = {"id": cover_art_id, "size": 2000, **self._get_params()} params = {"id": cover_art_id, "size": 2000, **self._get_params()}
return self._make_url("getCoverArt") + "?" + urlencode(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()} params = {"id": song_id, **self._get_params()}
endpoint = "stream" if stream else "download" endpoint = "stream" if stream else "download"
return self._make_url(endpoint) + "?" + urlencode(params) return self._make_url(endpoint) + "?" + urlencode(params)

View File

@@ -598,7 +598,8 @@ class SublimeMusicApp(Gtk.Application):
self.update_window() self.update_window()
@dbus_propagate() @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: if self.app_config.state.current_song is None:
insert_at = 0 insert_at = 0
else: else:
@@ -614,8 +615,7 @@ class SublimeMusicApp(Gtk.Application):
@dbus_propagate() @dbus_propagate()
def on_add_to_queue(self, action: Any, song_ids: GLib.Variant): def on_add_to_queue(self, action: Any, song_ids: GLib.Variant):
print(song_ids) song_ids = tuple(song_ids)
print(type(song_ids))
self.app_config.state.play_queue += tuple(song_ids) self.app_config.state.play_queue += tuple(song_ids)
self.app_config.state.old_play_queue += tuple(song_ids) self.app_config.state.old_play_queue += tuple(song_ids)
self.update_window() self.update_window()
@@ -719,7 +719,6 @@ class SublimeMusicApp(Gtk.Application):
song_queue: Tuple[str, ...], song_queue: Tuple[str, ...],
metadata: Dict[str, Any], metadata: Dict[str, Any],
): ):
print(type(song_queue), song_queue)
song_queue = tuple(song_queue) song_queue = tuple(song_queue)
# Reset the play queue so that we don't ever revert back to the # Reset the play queue so that we don't ever revert back to the
# previous one. # previous one.
@@ -1114,8 +1113,8 @@ class SublimeMusicApp(Gtk.Application):
play_queue_len: int = len(self.app_config.state.play_queue) play_queue_len: int = len(self.app_config.state.play_queue)
if is_repeat_queue or prefetch_idx < play_queue_len: if is_repeat_queue or prefetch_idx < play_queue_len:
prefetch_idxs.append( prefetch_idxs.append(
prefetch_idx % play_queue_len prefetch_idx % play_queue_len # noqa: S001
) # noqa: S001 )
AdapterManager.batch_download_songs( AdapterManager.batch_download_songs(
[self.app_config.state.play_queue[i] for i in prefetch_idxs], [self.app_config.state.play_queue[i] for i in prefetch_idxs],
before_download=lambda: self.update_window(), before_download=lambda: self.update_window(),

View File

@@ -16,7 +16,6 @@ from typing import (
import gi import gi
from deepdiff import DeepDiff from deepdiff import DeepDiff
gi.require_version("Gtk", "3.0") gi.require_version("Gtk", "3.0")
from gi.repository import Gdk, GLib, Gtk from gi.repository import Gdk, GLib, Gtk

View File

@@ -1,4 +1,5 @@
from time import sleep from time import sleep
from sublime.adapters import Result from sublime.adapters import Result
@@ -11,7 +12,7 @@ def test_result_immediate():
def test_result_immediate_callback(): def test_result_immediate_callback():
callback_called = True callback_called = True
def check_done_callback(f): def check_done_callback(f: Result):
nonlocal callback_called nonlocal callback_called
assert f.result() == 42 assert f.result() == 42
callback_called = True callback_called = True
@@ -22,7 +23,7 @@ def test_result_immediate_callback():
def test_result_future(): def test_result_future():
def resolve_later(): def resolve_later() -> int:
sleep(1) sleep(1)
return 42 return 42
@@ -33,13 +34,13 @@ def test_result_future():
def test_result_future_callback(): def test_result_future_callback():
def resolve_later(): def resolve_later() -> int:
sleep(1) sleep(1)
return 42 return 42
check_done = False check_done = False
def check_done_callback(f): def check_done_callback(f: Result):
nonlocal check_done nonlocal check_done
assert result.data_is_available assert result.data_is_available
assert f.result() == 42 assert f.result() == 42

View File

@@ -66,7 +66,7 @@ def mock_data_files_multi_part(
aggregate.append(line) aggregate.append(line)
parts.append("\n".join(aggregate)) parts.append("\n".join(aggregate))
print(parts) print(parts) # noqa: T001
yield file, iter(parts) yield file, iter(parts)