flake8: fix PEP8 warnings about lambda
Fix the 'lambda to def' warnings
This commit is contained in:
parent
4bf7a568d1
commit
34ada2784a
@ -25,7 +25,9 @@ class Scanner(object):
|
|||||||
sink = gst.element_factory_make('fakesink')
|
sink = gst.element_factory_make('fakesink')
|
||||||
|
|
||||||
audio_caps = gst.Caps(b'audio/x-raw-int; audio/x-raw-float')
|
audio_caps = gst.Caps(b'audio/x-raw-int; audio/x-raw-float')
|
||||||
pad_added = lambda src, pad: pad.link(sink.get_pad('sink'))
|
|
||||||
|
def pad_added(src, pad):
|
||||||
|
return pad.link(sink.get_pad('sink'))
|
||||||
|
|
||||||
self._uribin = gst.element_factory_make('uridecodebin')
|
self._uribin = gst.element_factory_make('uridecodebin')
|
||||||
self._uribin.set_property('caps', audio_caps)
|
self._uribin.set_property('caps', audio_caps)
|
||||||
|
|||||||
@ -113,7 +113,9 @@ class Backends(list):
|
|||||||
self.with_playlists = collections.OrderedDict()
|
self.with_playlists = collections.OrderedDict()
|
||||||
|
|
||||||
backends_by_scheme = {}
|
backends_by_scheme = {}
|
||||||
name = lambda b: b.actor_ref.actor_class.__name__
|
|
||||||
|
def name(b):
|
||||||
|
return b.actor_ref.actor_class.__name__
|
||||||
|
|
||||||
for b in backends:
|
for b in backends:
|
||||||
has_library = b.has_library().get()
|
has_library = b.has_library().get()
|
||||||
|
|||||||
@ -21,37 +21,52 @@ def find_exact(tracks, query=None, uris=None):
|
|||||||
else:
|
else:
|
||||||
q = value.strip()
|
q = value.strip()
|
||||||
|
|
||||||
uri_filter = lambda t: q == t.uri
|
def uri_filter(t):
|
||||||
track_name_filter = lambda t: q == t.name
|
return q == t.uri
|
||||||
album_filter = lambda t: q == getattr(
|
|
||||||
getattr(t, 'album', None), 'name', None)
|
def track_name_filter(t):
|
||||||
artist_filter = lambda t: filter(
|
return q == t.name
|
||||||
lambda a: q == a.name, t.artists)
|
|
||||||
albumartist_filter = lambda t: any([
|
def album_filter(t):
|
||||||
q == a.name
|
return q == getattr(getattr(t, 'album', None), 'name', None)
|
||||||
for a in getattr(t.album, 'artists', [])])
|
|
||||||
composer_filter = lambda t: any([
|
def artist_filter(t):
|
||||||
q == a.name
|
return filter(lambda a: q == a.name, t.artists)
|
||||||
for a in getattr(t, 'composers', [])])
|
|
||||||
performer_filter = lambda t: any([
|
def albumartist_filter(t):
|
||||||
q == a.name
|
return any([q == a.name for a in getattr(t.album,
|
||||||
for a in getattr(t, 'performers', [])])
|
'artists', [])])
|
||||||
track_no_filter = lambda t: q == t.track_no
|
|
||||||
genre_filter = lambda t: t.genre and q == t.genre
|
def composer_filter(t):
|
||||||
date_filter = lambda t: q == t.date
|
return any([q == a.name for a in getattr(t, 'composers', [])])
|
||||||
comment_filter = lambda t: q == t.comment
|
|
||||||
any_filter = lambda t: (
|
def performer_filter(t):
|
||||||
uri_filter(t) or
|
return any([q == a.name for a in getattr(t, 'performers', [])])
|
||||||
track_name_filter(t) or
|
|
||||||
album_filter(t) or
|
def track_no_filter(t):
|
||||||
artist_filter(t) or
|
return q == t.track_no
|
||||||
albumartist_filter(t) or
|
|
||||||
composer_filter(t) or
|
def genre_filter(t):
|
||||||
performer_filter(t) or
|
return (t.genre and q == t.genre)
|
||||||
track_no_filter(t) or
|
|
||||||
genre_filter(t) or
|
def date_filter(t):
|
||||||
date_filter(t) or
|
return q == t.date
|
||||||
comment_filter(t))
|
|
||||||
|
def comment_filter(t):
|
||||||
|
return q == t.comment
|
||||||
|
|
||||||
|
def any_filter(t):
|
||||||
|
return (uri_filter(t) or
|
||||||
|
track_name_filter(t) or
|
||||||
|
album_filter(t) or
|
||||||
|
artist_filter(t) or
|
||||||
|
albumartist_filter(t) or
|
||||||
|
composer_filter(t) or
|
||||||
|
performer_filter(t) or
|
||||||
|
track_no_filter(t) or
|
||||||
|
genre_filter(t) or
|
||||||
|
date_filter(t) or
|
||||||
|
comment_filter(t))
|
||||||
|
|
||||||
if field == 'uri':
|
if field == 'uri':
|
||||||
tracks = filter(uri_filter, tracks)
|
tracks = filter(uri_filter, tracks)
|
||||||
@ -102,38 +117,56 @@ def search(tracks, query=None, uris=None):
|
|||||||
else:
|
else:
|
||||||
q = value.strip().lower()
|
q = value.strip().lower()
|
||||||
|
|
||||||
uri_filter = lambda t: bool(t.uri and q in t.uri.lower())
|
def uri_filter(t):
|
||||||
track_name_filter = lambda t: bool(t.name and q in t.name.lower())
|
return bool(t.uri and q in t.uri.lower())
|
||||||
album_filter = lambda t: bool(
|
|
||||||
t.album and t.album.name and q in t.album.name.lower())
|
def track_name_filter(t):
|
||||||
artist_filter = lambda t: bool(filter(
|
return bool(t.name and q in t.name.lower())
|
||||||
lambda a: bool(a.name and q in a.name.lower()), t.artists))
|
|
||||||
albumartist_filter = lambda t: any([
|
def album_filter(t):
|
||||||
a.name and q in a.name.lower()
|
return bool(t.album and t.album.name
|
||||||
for a in getattr(t.album, 'artists', [])])
|
and q in t.album.name.lower())
|
||||||
composer_filter = lambda t: any([
|
|
||||||
a.name and q in a.name.lower()
|
def artist_filter(t):
|
||||||
for a in getattr(t, 'composers', [])])
|
return bool(filter(lambda a:
|
||||||
performer_filter = lambda t: any([
|
bool(a.name and q in a.name.lower()), t.artists))
|
||||||
a.name and q in a.name.lower()
|
|
||||||
for a in getattr(t, 'performers', [])])
|
def albumartist_filter(t):
|
||||||
track_no_filter = lambda t: q == t.track_no
|
return any([a.name and q in a.name.lower()
|
||||||
genre_filter = lambda t: bool(t.genre and q in t.genre.lower())
|
for a in getattr(t.album, 'artists', [])])
|
||||||
date_filter = lambda t: bool(t.date and t.date.startswith(q))
|
|
||||||
comment_filter = lambda t: bool(
|
def composer_filter(t):
|
||||||
t.comment and q in t.comment.lower())
|
return any([a.name and q in a.name.lower()
|
||||||
any_filter = lambda t: (
|
for a in getattr(t, 'composers', [])])
|
||||||
uri_filter(t) or
|
|
||||||
track_name_filter(t) or
|
def performer_filter(t):
|
||||||
album_filter(t) or
|
return any([a.name and q in a.name.lower()
|
||||||
artist_filter(t) or
|
for a in getattr(t, 'performers', [])])
|
||||||
albumartist_filter(t) or
|
|
||||||
composer_filter(t) or
|
def track_no_filter(t):
|
||||||
performer_filter(t) or
|
return q == t.track_no
|
||||||
track_no_filter(t) or
|
|
||||||
genre_filter(t) or
|
def genre_filter(t):
|
||||||
date_filter(t) or
|
return bool(t.genre and q in t.genre.lower())
|
||||||
comment_filter(t))
|
|
||||||
|
def date_filter(t):
|
||||||
|
return bool(t.date and t.date.startswith(q))
|
||||||
|
|
||||||
|
def comment_filter(t):
|
||||||
|
return bool(t.comment and q in t.comment.lower())
|
||||||
|
|
||||||
|
def any_filter(t):
|
||||||
|
return (uri_filter(t) or
|
||||||
|
track_name_filter(t) or
|
||||||
|
album_filter(t) or
|
||||||
|
artist_filter(t) or
|
||||||
|
albumartist_filter(t) or
|
||||||
|
composer_filter(t) or
|
||||||
|
performer_filter(t) or
|
||||||
|
track_no_filter(t) or
|
||||||
|
genre_filter(t) or
|
||||||
|
date_filter(t) or
|
||||||
|
comment_filter(t))
|
||||||
|
|
||||||
if field == 'uri':
|
if field == 'uri':
|
||||||
tracks = filter(uri_filter, tracks)
|
tracks = filter(uri_filter, tracks)
|
||||||
|
|||||||
@ -367,7 +367,9 @@ class Track(ImmutableObject):
|
|||||||
last_modified = None
|
last_modified = None
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
get = lambda key: frozenset(kwargs.pop(key, None) or [])
|
def get(key):
|
||||||
|
return frozenset(kwargs.pop(key, None) or [])
|
||||||
|
|
||||||
self.__dict__['artists'] = get('artists')
|
self.__dict__['artists'] = get('artists')
|
||||||
self.__dict__['composers'] = get('composers')
|
self.__dict__['composers'] = get('composers')
|
||||||
self.__dict__['performers'] = get('performers')
|
self.__dict__['performers'] = get('performers')
|
||||||
|
|||||||
@ -3,8 +3,7 @@ application-import-names = mopidy,tests
|
|||||||
exclude = .git,.tox,build,js
|
exclude = .git,.tox,build,js
|
||||||
# Ignored flake8 warnings:
|
# Ignored flake8 warnings:
|
||||||
# - E402 module level import not at top of file
|
# - E402 module level import not at top of file
|
||||||
# - E731 do not assign a lambda expression, use a def
|
ignore = E402
|
||||||
ignore = E402,E731
|
|
||||||
|
|
||||||
[wheel]
|
[wheel]
|
||||||
universal = 1
|
universal = 1
|
||||||
|
|||||||
@ -64,7 +64,8 @@ class TestCommands(unittest.TestCase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def test_register_second_command_to_same_name_fails(self):
|
def test_register_second_command_to_same_name_fails(self):
|
||||||
func = lambda context: True
|
def func(context):
|
||||||
|
pass
|
||||||
|
|
||||||
self.commands.add('foo')(func)
|
self.commands.add('foo')(func)
|
||||||
with self.assertRaises(Exception):
|
with self.assertRaises(Exception):
|
||||||
@ -88,7 +89,10 @@ class TestCommands(unittest.TestCase):
|
|||||||
|
|
||||||
def test_function_has_required_and_optional_args_succeeds(self):
|
def test_function_has_required_and_optional_args_succeeds(self):
|
||||||
sentinel = object()
|
sentinel = object()
|
||||||
func = lambda context, required, optional=None: sentinel
|
|
||||||
|
def func(context, required, optional=None):
|
||||||
|
return sentinel
|
||||||
|
|
||||||
self.commands.add('bar')(func)
|
self.commands.add('bar')(func)
|
||||||
self.assertEqual(sentinel, self.commands.call(['bar', 'arg']))
|
self.assertEqual(sentinel, self.commands.call(['bar', 'arg']))
|
||||||
self.assertEqual(sentinel, self.commands.call(['bar', 'arg', 'arg']))
|
self.assertEqual(sentinel, self.commands.call(['bar', 'arg', 'arg']))
|
||||||
@ -111,12 +115,16 @@ class TestCommands(unittest.TestCase):
|
|||||||
|
|
||||||
def test_function_has_required_and_varargs_fails(self):
|
def test_function_has_required_and_varargs_fails(self):
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
func = lambda context, required, *args: True
|
def func(context, required, *args):
|
||||||
|
pass
|
||||||
|
|
||||||
self.commands.add('test')(func)
|
self.commands.add('test')(func)
|
||||||
|
|
||||||
def test_function_has_optional_and_varargs_fails(self):
|
def test_function_has_optional_and_varargs_fails(self):
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
func = lambda context, optional=None, *args: True
|
def func(context, optional=None, *args):
|
||||||
|
pass
|
||||||
|
|
||||||
self.commands.add('test')(func)
|
self.commands.add('test')(func)
|
||||||
|
|
||||||
def test_function_hash_keywordargs_fails(self):
|
def test_function_hash_keywordargs_fails(self):
|
||||||
@ -158,7 +166,9 @@ class TestCommands(unittest.TestCase):
|
|||||||
self.assertEqual('test', self.commands.call(['foo', 'test']))
|
self.assertEqual('test', self.commands.call(['foo', 'test']))
|
||||||
|
|
||||||
def test_call_passes_required_and_optional_argument(self):
|
def test_call_passes_required_and_optional_argument(self):
|
||||||
func = lambda context, required, optional=None: (required, optional)
|
def func(context, required, optional=None):
|
||||||
|
return (required, optional)
|
||||||
|
|
||||||
self.commands.add('foo')(func)
|
self.commands.add('foo')(func)
|
||||||
self.assertEqual(('arg', None), self.commands.call(['foo', 'arg']))
|
self.assertEqual(('arg', None), self.commands.call(['foo', 'arg']))
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@ -182,20 +192,29 @@ class TestCommands(unittest.TestCase):
|
|||||||
|
|
||||||
def test_validator_gets_applied_to_required_arg(self):
|
def test_validator_gets_applied_to_required_arg(self):
|
||||||
sentinel = object()
|
sentinel = object()
|
||||||
func = lambda context, required: required
|
|
||||||
|
def func(context, required):
|
||||||
|
return required
|
||||||
|
|
||||||
self.commands.add('test', required=lambda v: sentinel)(func)
|
self.commands.add('test', required=lambda v: sentinel)(func)
|
||||||
self.assertEqual(sentinel, self.commands.call(['test', 'foo']))
|
self.assertEqual(sentinel, self.commands.call(['test', 'foo']))
|
||||||
|
|
||||||
def test_validator_gets_applied_to_optional_arg(self):
|
def test_validator_gets_applied_to_optional_arg(self):
|
||||||
sentinel = object()
|
sentinel = object()
|
||||||
func = lambda context, optional=None: optional
|
|
||||||
|
def func(context, optional=None):
|
||||||
|
return optional
|
||||||
|
|
||||||
self.commands.add('foo', optional=lambda v: sentinel)(func)
|
self.commands.add('foo', optional=lambda v: sentinel)(func)
|
||||||
|
|
||||||
self.assertEqual(sentinel, self.commands.call(['foo', '123']))
|
self.assertEqual(sentinel, self.commands.call(['foo', '123']))
|
||||||
|
|
||||||
def test_validator_skips_optional_default(self):
|
def test_validator_skips_optional_default(self):
|
||||||
sentinel = object()
|
sentinel = object()
|
||||||
func = lambda context, optional=sentinel: optional
|
|
||||||
|
def func(context, optional=sentinel):
|
||||||
|
return optional
|
||||||
|
|
||||||
self.commands.add('foo', optional=lambda v: None)(func)
|
self.commands.add('foo', optional=lambda v: None)(func)
|
||||||
|
|
||||||
self.assertEqual(sentinel, self.commands.call(['foo']))
|
self.assertEqual(sentinel, self.commands.call(['foo']))
|
||||||
@ -203,28 +222,38 @@ class TestCommands(unittest.TestCase):
|
|||||||
def test_validator_applied_to_non_existent_arg_fails(self):
|
def test_validator_applied_to_non_existent_arg_fails(self):
|
||||||
self.commands.add('foo')(lambda context, arg: arg)
|
self.commands.add('foo')(lambda context, arg: arg)
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
func = lambda context, wrong_arg: wrong_arg
|
def func(context, wrong_arg):
|
||||||
|
return wrong_arg
|
||||||
|
|
||||||
self.commands.add('bar', arg=lambda v: v)(func)
|
self.commands.add('bar', arg=lambda v: v)(func)
|
||||||
|
|
||||||
def test_validator_called_context_fails(self):
|
def test_validator_called_context_fails(self):
|
||||||
return # TODO: how to handle this
|
return # TODO: how to handle this
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
func = lambda context: True
|
def func(context):
|
||||||
|
pass
|
||||||
|
|
||||||
self.commands.add('bar', context=lambda v: v)(func)
|
self.commands.add('bar', context=lambda v: v)(func)
|
||||||
|
|
||||||
def test_validator_value_error_is_converted(self):
|
def test_validator_value_error_is_converted(self):
|
||||||
def validdate(value):
|
def validdate(value):
|
||||||
raise ValueError
|
raise ValueError
|
||||||
|
|
||||||
func = lambda context, arg: True
|
def func(context, arg):
|
||||||
|
pass
|
||||||
|
|
||||||
self.commands.add('bar', arg=validdate)(func)
|
self.commands.add('bar', arg=validdate)(func)
|
||||||
|
|
||||||
with self.assertRaises(exceptions.MpdArgError):
|
with self.assertRaises(exceptions.MpdArgError):
|
||||||
self.commands.call(['bar', 'test'])
|
self.commands.call(['bar', 'test'])
|
||||||
|
|
||||||
def test_auth_required_gets_stored(self):
|
def test_auth_required_gets_stored(self):
|
||||||
func1 = lambda context: context
|
def func1(context):
|
||||||
func2 = lambda context: context
|
pass
|
||||||
|
|
||||||
|
def func2(context):
|
||||||
|
pass
|
||||||
|
|
||||||
self.commands.add('foo')(func1)
|
self.commands.add('foo')(func1)
|
||||||
self.commands.add('bar', auth_required=False)(func2)
|
self.commands.add('bar', auth_required=False)(func2)
|
||||||
|
|
||||||
@ -232,8 +261,12 @@ class TestCommands(unittest.TestCase):
|
|||||||
self.assertFalse(self.commands.handlers['bar'].auth_required)
|
self.assertFalse(self.commands.handlers['bar'].auth_required)
|
||||||
|
|
||||||
def test_list_command_gets_stored(self):
|
def test_list_command_gets_stored(self):
|
||||||
func1 = lambda context: context
|
def func1(context):
|
||||||
func2 = lambda context: context
|
pass
|
||||||
|
|
||||||
|
def func2(context):
|
||||||
|
pass
|
||||||
|
|
||||||
self.commands.add('foo')(func1)
|
self.commands.add('foo')(func1)
|
||||||
self.commands.add('bar', list_command=False)(func2)
|
self.commands.add('bar', list_command=False)(func2)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user