From 79858975a9bc007680a8241e666c8b6e8f4a35a0 Mon Sep 17 00:00:00 2001 From: Aksh Gupta Date: Wed, 10 Mar 2021 13:07:43 +0530 Subject: [PATCH] chore: refactor code quality issues --- beets/dbcore/db.py | 4 ++-- beets/importer.py | 2 +- beets/ui/__init__.py | 2 +- beetsplug/bpd/__init__.py | 3 ++- beetsplug/export.py | 2 +- beetsplug/fetchart.py | 2 +- beetsplug/fish.py | 4 ++-- beetsplug/importadded.py | 2 +- beetsplug/info.py | 2 +- beetsplug/mbsync.py | 2 +- beetsplug/missing.py | 2 +- beetsplug/replaygain.py | 6 +++--- beetsplug/subsonicplaylist.py | 4 ++-- 13 files changed, 19 insertions(+), 18 deletions(-) diff --git a/beets/dbcore/db.py b/beets/dbcore/db.py index 409ecc9af..b87b41644 100755 --- a/beets/dbcore/db.py +++ b/beets/dbcore/db.py @@ -729,10 +729,10 @@ class Results(object): def _get_indexed_flex_attrs(self): """ Index flexible attributes by the entity id they belong to """ - flex_values = dict() + flex_values = {} for row in self.flex_rows: if row['entity_id'] not in flex_values: - flex_values[row['entity_id']] = dict() + flex_values[row['entity_id']] = {} flex_values[row['entity_id']][row['key']] = row['value'] diff --git a/beets/importer.py b/beets/importer.py index c5701ff30..b7bfdb156 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -187,7 +187,7 @@ class ImportSession(object): self.logger = self._setup_logging(loghandler) self.paths = paths self.query = query - self._is_resuming = dict() + self._is_resuming = {} self._merged_items = set() self._merged_dirs = set() diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index 362e8752a..3d7cffb51 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -791,7 +791,7 @@ def _store_dict(option, opt_str, value, parser): if option_values is None: # This is the first supplied ``key=value`` pair of option. # Initialize empty dictionary and get a reference to it. - setattr(parser.values, dest, dict()) + setattr(parser.values, dest, {}) option_values = getattr(parser.values, dest) try: diff --git a/beetsplug/bpd/__init__.py b/beetsplug/bpd/__init__.py index dad864b8b..628353942 100644 --- a/beetsplug/bpd/__init__.py +++ b/beetsplug/bpd/__init__.py @@ -21,6 +21,7 @@ use of the wide range of MPD clients. from __future__ import division, absolute_import, print_function import re +import sys from string import Template import traceback import random @@ -334,7 +335,7 @@ class BaseServer(object): def cmd_kill(self, conn): """Exits the server process.""" - exit(0) + sys.exit(0) def cmd_close(self, conn): """Closes the connection.""" diff --git a/beetsplug/export.py b/beetsplug/export.py index 957180db2..3ce9ab887 100644 --- a/beetsplug/export.py +++ b/beetsplug/export.py @@ -33,7 +33,7 @@ from beetsplug.info import make_key_filter, library_data, tag_data class ExportEncoder(json.JSONEncoder): """Deals with dates because JSON doesn't have a standard""" def default(self, o): - if isinstance(o, datetime) or isinstance(o, date): + if isinstance(o, (datetime, date)): return o.isoformat() return json.JSONEncoder.default(self, o) diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index 1bf8ad428..14323507a 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -504,7 +504,7 @@ class FanartTV(RemoteArtSource): matches = [] # can there be more than one releasegroupid per response? - for mbid, art in data.get(u'albums', dict()).items(): + for mbid, art in data.get(u'albums', {}).items(): # there might be more art referenced, e.g. cdart, and an albumcover # might not be present, even if the request was successful if album.mb_releasegroupid == mbid and u'albumcover' in art: diff --git a/beetsplug/fish.py b/beetsplug/fish.py index 12f474e88..b4c28c283 100644 --- a/beetsplug/fish.py +++ b/beetsplug/fish.py @@ -110,7 +110,7 @@ class FishPlugin(BeetsPlugin): # Collect commands, their aliases, and their help text cmd_names_help = [] for cmd in beetcmds: - names = [alias for alias in cmd.aliases] + names = list(cmd.aliases) names.append(cmd.name) for name in names: cmd_names_help.append((name, cmd.help)) @@ -238,7 +238,7 @@ def get_all_commands(beetcmds): # Formatting for Fish to complete command options word = "" for cmd in beetcmds: - names = [alias for alias in cmd.aliases] + names = list(cmd.aliases) names.append(cmd.name) for name in names: name = _escape(name) diff --git a/beetsplug/importadded.py b/beetsplug/importadded.py index 29aeeab0f..37e881e96 100644 --- a/beetsplug/importadded.py +++ b/beetsplug/importadded.py @@ -27,7 +27,7 @@ class ImportAddedPlugin(BeetsPlugin): # album.path for old albums that were replaced by a reimported album self.replaced_album_paths = None # item path in the library to the mtime of the source file - self.item_mtime = dict() + self.item_mtime = {} register = self.register_listener register('import_task_created', self.check_config) diff --git a/beetsplug/info.py b/beetsplug/info.py index b8a0c9375..05d215e7b 100644 --- a/beetsplug/info.py +++ b/beetsplug/info.py @@ -235,7 +235,7 @@ def make_key_filter(include): matchers.append(re.compile(key + '$')) def filter_(data): - filtered = dict() + filtered = {} for key, value in data.items(): if any([m.match(key) for m in matchers]): filtered[key] = value diff --git a/beetsplug/mbsync.py b/beetsplug/mbsync.py index a2b3bc4aa..ee2c4b5bd 100644 --- a/beetsplug/mbsync.py +++ b/beetsplug/mbsync.py @@ -123,7 +123,7 @@ class MBSyncPlugin(BeetsPlugin): # Map release track and recording MBIDs to their information. # Recordings can appear multiple times on a release, so each MBID # maps to a list of TrackInfo objects. - releasetrack_index = dict() + releasetrack_index = {} track_index = defaultdict(list) for track_info in album_info.tracks: releasetrack_index[track_info.release_track_id] = track_info diff --git a/beetsplug/missing.py b/beetsplug/missing.py index 8f0790f2b..247ccc999 100644 --- a/beetsplug/missing.py +++ b/beetsplug/missing.py @@ -216,7 +216,7 @@ class MissingPlugin(BeetsPlugin): """Query MusicBrainz to determine items missing from `album`. """ item_mbids = [x.mb_trackid for x in album.items()] - if len([i for i in album.items()]) < album.albumtotal: + if len(list(album.items())) < album.albumtotal: # fetch missing items # TODO: Implement caching that without breaking other stuff album_info = hooks.album_for_mbid(album.mb_albumid) diff --git a/beetsplug/replaygain.py b/beetsplug/replaygain.py index 5060c8efe..8b9447bdb 100644 --- a/beetsplug/replaygain.py +++ b/beetsplug/replaygain.py @@ -1139,7 +1139,7 @@ class ReplayGainPlugin(BeetsPlugin): tag_vals = self.tag_specific_values(album.items()) store_track_gain, store_album_gain, target_level, peak = tag_vals - discs = dict() + discs = {} if self.per_disc: for item in album.items(): if discs.get(item.disc) is None: @@ -1172,7 +1172,7 @@ class ReplayGainPlugin(BeetsPlugin): self._apply( self.backend_instance.compute_album_gain, args=(), kwds={ - "items": [i for i in items], + "items": list(items), "target_level": target_level, "peak": peak }, @@ -1288,7 +1288,7 @@ class ReplayGainPlugin(BeetsPlugin): try: self._log.info('interrupted') self.terminate_pool() - exit(0) + sys.exit(0) except SystemExit: # Silence raised SystemExit ~ exit(0) pass diff --git a/beetsplug/subsonicplaylist.py b/beetsplug/subsonicplaylist.py index 732b51c2f..5d64708ad 100644 --- a/beetsplug/subsonicplaylist.py +++ b/beetsplug/subsonicplaylist.py @@ -148,7 +148,7 @@ class SubsonicPlaylistPlugin(BeetsPlugin): def send(self, endpoint, params=None): if params is None: - params = dict() + params = {} a, b = self.generate_token() params['u'] = self.config['username'] params['t'] = a @@ -163,7 +163,7 @@ class SubsonicPlaylistPlugin(BeetsPlugin): return resp def get_playlists(self, ids): - output = dict() + output = {} for playlist_id in ids: name, tracks = self.get_playlist(playlist_id) for track in tracks: