replace some filter/map calls with list comps

These are places where the surrounding/calling code needs a list, not an iter.
This commit is contained in:
Johnny Robeson 2016-06-08 00:17:18 -04:00
parent be474b3f52
commit 790b1b5153
4 changed files with 8 additions and 9 deletions

View file

@ -547,7 +547,7 @@ def albums_for_id(album_id):
for a in plugin_albums:
plugins.send(u'albuminfo_received', info=a)
candidates.extend(plugin_albums)
return filter(None, candidates)
return [a for a in candidates if a]
def tracks_for_id(track_id):
@ -557,7 +557,7 @@ def tracks_for_id(track_id):
for t in plugin_tracks:
plugins.send(u'trackinfo_received', info=t)
candidates.extend(plugin_tracks)
return filter(None, candidates)
return [t for t in candidates if t]
def album_candidates(items, artist, album, va_likely):

View file

@ -133,7 +133,7 @@ class MissingPlugin(BeetsPlugin):
def _missing(self, album):
"""Query MusicBrainz to determine items missing from `album`.
"""
item_mbids = map(lambda x: x.mb_trackid, album.items())
item_mbids = [x.mb_trackid for x in album.items()]
if len([i for i in album.items()]) < album.albumtotal:
# fetch missing items
# TODO: Implement caching that without breaking other stuff

View file

@ -124,9 +124,8 @@ class SpotifyPlugin(BeetsPlugin):
# Apply market filter if requested
region_filter = self.config['region_filter'].get()
if region_filter:
r_data = filter(
lambda x: region_filter in x['available_markets'], r_data
)
r_data = [x for x in r_data if region_filter
in x['available_markets']]
# Simplest, take the first result
chosen_result = None
@ -163,7 +162,7 @@ class SpotifyPlugin(BeetsPlugin):
def output_results(self, results):
if results:
ids = map(lambda x: x['id'], results)
ids = [x['id'] for x in results]
if self.config['mode'].get() == "open":
self._log.info(u'Attempting to open Spotify with playlist')
spotify_url = self.playlist_partial + ",".join(ids)

View file

@ -37,11 +37,11 @@ from beets import util
class TestHelper(helper.TestHelper):
def assertInResult(self, item, results): # noqa
result_ids = map(lambda i: i.id, results)
result_ids = [i.id for i in results]
self.assertIn(item.id, result_ids)
def assertNotInResult(self, item, results): # noqa
result_ids = map(lambda i: i.id, results)
result_ids = [i.id for i in results]
self.assertNotIn(item.id, result_ids)