Skip to content

Commit 92c118f

Browse files
committed
Corrected some flake8 errors
1 parent 6664b65 commit 92c118f

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

beets/dbcore/query.py

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class InvalidQueryError(ParsingError):
4040
4141
The query should be a unicode string or a list, which will be space-joined.
4242
"""
43+
4344
def __init__(self, query, explanation):
4445
if isinstance(query, list):
4546
query = " ".join(query)
@@ -53,6 +54,7 @@ class InvalidQueryArgumentValueError(ParsingError):
5354
It exists to be caught in upper stack levels so a meaningful (i.e. with the
5455
query) InvalidQueryError can be raised.
5556
"""
57+
5658
def __init__(self, what, expected, detail=None):
5759
message = u"'{0}' is not {1}".format(what, expected)
5860
if detail:
@@ -63,6 +65,7 @@ def __init__(self, what, expected, detail=None):
6365
class Query(object):
6466
"""An abstract class representing a query into the item database.
6567
"""
68+
6669
def clause(self):
6770
"""Generate an SQLite expression implementing the query.
6871
@@ -95,6 +98,7 @@ class FieldQuery(Query):
9598
string. Subclasses may also provide `col_clause` to implement the
9699
same matching functionality in SQLite.
97100
"""
101+
98102
def __init__(self, field, pattern, fast=True):
99103
self.field = field
100104
self.pattern = pattern
@@ -126,14 +130,15 @@ def __repr__(self):
126130

127131
def __eq__(self, other):
128132
return super(FieldQuery, self).__eq__(other) and \
129-
self.field == other.field and self.pattern == other.pattern
133+
self.field == other.field and self.pattern == other.pattern
130134

131135
def __hash__(self):
132136
return hash((self.field, hash(self.pattern)))
133137

134138

135139
class MatchQuery(FieldQuery):
136140
"""A query that looks for exact matches in an item field."""
141+
137142
def col_clause(self):
138143
return self.field + " = ?", [self.pattern]
139144

@@ -143,7 +148,6 @@ def value_match(cls, pattern, value):
143148

144149

145150
class NoneQuery(FieldQuery):
146-
147151
def __init__(self, field, fast=True):
148152
super(NoneQuery, self).__init__(field, None, fast)
149153

@@ -165,6 +169,7 @@ class StringFieldQuery(FieldQuery):
165169
"""A FieldQuery that converts values to strings before matching
166170
them.
167171
"""
172+
168173
@classmethod
169174
def value_match(cls, pattern, value):
170175
"""Determine whether the value matches the pattern. The value
@@ -182,11 +187,12 @@ def string_match(cls, pattern, value):
182187

183188
class SubstringQuery(StringFieldQuery):
184189
"""A query that matches a substring in a specific item field."""
190+
185191
def col_clause(self):
186192
pattern = (self.pattern
187-
.replace('\\', '\\\\')
188-
.replace('%', '\\%')
189-
.replace('_', '\\_'))
193+
.replace('\\', '\\\\')
194+
.replace('%', '\\%')
195+
.replace('_', '\\_'))
190196
search = '%' + pattern + '%'
191197
clause = self.field + " like ? escape '\\'"
192198
subvals = [search]
@@ -204,6 +210,7 @@ class RegexpQuery(StringFieldQuery):
204210
Raises InvalidQueryError when the pattern is not a valid regular
205211
expression.
206212
"""
213+
207214
def __init__(self, field, pattern, fast=True):
208215
super(RegexpQuery, self).__init__(field, pattern, fast)
209216
pattern = self._normalize(pattern)
@@ -231,6 +238,7 @@ class BooleanQuery(MatchQuery):
231238
"""Matches a boolean field. Pattern should either be a boolean or a
232239
string reflecting a boolean.
233240
"""
241+
234242
def __init__(self, field, pattern, fast=True):
235243
super(BooleanQuery, self).__init__(field, pattern, fast)
236244
if isinstance(pattern, six.string_types):
@@ -244,6 +252,7 @@ class BytesQuery(MatchQuery):
244252
`unicode` equivalently in Python 2. Always use this query instead of
245253
`MatchQuery` when matching on BLOB values.
246254
"""
255+
247256
def __init__(self, field, pattern):
248257
super(BytesQuery, self).__init__(field, pattern)
249258

@@ -270,6 +279,7 @@ class NumericQuery(FieldQuery):
270279
Raises InvalidQueryError when the pattern does not represent an int or
271280
a float.
272281
"""
282+
273283
def _convert(self, s):
274284
"""Convert a string to a numeric type (float or int).
275285
@@ -337,6 +347,7 @@ class CollectionQuery(Query):
337347
"""An abstract query class that aggregates other queries. Can be
338348
indexed like a list to access the sub-queries.
339349
"""
350+
340351
def __init__(self, subqueries=()):
341352
self.subqueries = subqueries
342353

@@ -375,7 +386,7 @@ def __repr__(self):
375386

376387
def __eq__(self, other):
377388
return super(CollectionQuery, self).__eq__(other) and \
378-
self.subqueries == other.subqueries
389+
self.subqueries == other.subqueries
379390

380391
def __hash__(self):
381392
"""Since subqueries are mutable, this object should not be hashable.
@@ -389,6 +400,7 @@ class AnyFieldQuery(CollectionQuery):
389400
any field. The individual field query class is provided to the
390401
constructor.
391402
"""
403+
392404
def __init__(self, pattern, fields, cls):
393405
self.pattern = pattern
394406
self.fields = fields
@@ -414,7 +426,7 @@ def __repr__(self):
414426

415427
def __eq__(self, other):
416428
return super(AnyFieldQuery, self).__eq__(other) and \
417-
self.query_class == other.query_class
429+
self.query_class == other.query_class
418430

419431
def __hash__(self):
420432
return hash((self.pattern, tuple(self.fields), self.query_class))
@@ -424,6 +436,7 @@ class MutableCollectionQuery(CollectionQuery):
424436
"""A collection query whose subqueries may be modified after the
425437
query is initialized.
426438
"""
439+
427440
def __setitem__(self, key, value):
428441
self.subqueries[key] = value
429442

@@ -433,6 +446,7 @@ def __delitem__(self, key):
433446

434447
class AndQuery(MutableCollectionQuery):
435448
"""A conjunction of a list of other queries."""
449+
436450
def clause(self):
437451
return self.clause_with_joiner('and')
438452

@@ -442,6 +456,7 @@ def match(self, item):
442456

443457
class OrQuery(MutableCollectionQuery):
444458
"""A conjunction of a list of other queries."""
459+
445460
def clause(self):
446461
return self.clause_with_joiner('or')
447462

@@ -453,6 +468,7 @@ class NotQuery(Query):
453468
"""A query that matches the negation of its `subquery`, as a shorcut for
454469
performing `not(subquery)` without using regular expressions.
455470
"""
471+
456472
def __init__(self, subquery):
457473
self.subquery = subquery
458474

@@ -473,14 +489,15 @@ def __repr__(self):
473489

474490
def __eq__(self, other):
475491
return super(NotQuery, self).__eq__(other) and \
476-
self.subquery == other.subquery
492+
self.subquery == other.subquery
477493

478494
def __hash__(self):
479495
return hash(('not', hash(self.subquery)))
480496

481497

482498
class TrueQuery(Query):
483499
"""A query that always matches."""
500+
484501
def clause(self):
485502
return '1', ()
486503

@@ -490,6 +507,7 @@ def match(self, item):
490507

491508
class FalseQuery(Query):
492509
"""A query that never matches."""
510+
493511
def clause(self):
494512
return '0', ()
495513

@@ -533,7 +551,6 @@ class Period(object):
533551
instants of time during January 2014.
534552
"""
535553

536-
537554
precisions = ('year', 'month', 'day', 'hour', 'minute', 'second')
538555
date_formats = (
539556
('%Y',), # year
@@ -545,7 +562,6 @@ class Period(object):
545562
)
546563
relative = {'y': 365, 'm': 30, 'w': 7, 'd': 1}
547564

548-
549565
def __init__(self, date, precision):
550566
"""Create a period with the given date (a `datetime` object) and
551567
precision (a string, one of "year", "month", "day", "hour", "minute",
@@ -599,7 +615,8 @@ def find_date_and_format(string):
599615
timespan = match_dq.group('timespan')
600616
multiplier = -1 if sign == '-' else 1
601617
days = cls.relative[timespan]
602-
date = datetime.now() + multiplier * timedelta(days=int(quantity) * days)
618+
date = datetime.now() + multiplier * timedelta(
619+
days=int(quantity) * days)
603620
string = date.strftime(cls.date_formats[5][0])
604621

605622
date, ordinal = find_date_and_format(string)
@@ -838,13 +855,14 @@ def __hash__(self):
838855

839856
def __eq__(self, other):
840857
return super(MultipleSort, self).__eq__(other) and \
841-
self.sorts == other.sorts
858+
self.sorts == other.sorts
842859

843860

844861
class FieldSort(Sort):
845862
"""An abstract sort criterion that orders by a specific field (of
846863
any kind).
847864
"""
865+
848866
def __init__(self, field, ascending=True, case_insensitive=True):
849867
self.field = field
850868
self.ascending = ascending
@@ -875,13 +893,14 @@ def __hash__(self):
875893

876894
def __eq__(self, other):
877895
return super(FieldSort, self).__eq__(other) and \
878-
self.field == other.field and \
879-
self.ascending == other.ascending
896+
self.field == other.field and \
897+
self.ascending == other.ascending
880898

881899

882900
class FixedFieldSort(FieldSort):
883901
"""Sort object to sort on a fixed field.
884902
"""
903+
885904
def order_clause(self):
886905
order = "ASC" if self.ascending else "DESC"
887906
if self.case_insensitive:
@@ -898,12 +917,14 @@ class SlowFieldSort(FieldSort):
898917
"""A sort criterion by some model field other than a fixed field:
899918
i.e., a computed or flexible field.
900919
"""
920+
901921
def is_slow(self):
902922
return True
903923

904924

905925
class NullSort(Sort):
906926
"""No sorting. Leave results unsorted."""
927+
907928
def sort(self, items):
908929
return items
909930

0 commit comments

Comments
 (0)