Manual fixes for misreports from ruff

This commit is contained in:
Kovid Goyal 2023-01-09 19:13:32 +05:30
parent d7c31f4a81
commit a1d21e3632
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
7 changed files with 19 additions and 17 deletions

View File

@ -1,5 +0,0 @@
#!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: %YEAR%, %USER% <%MAIL%>
%HERE%

View File

@ -237,11 +237,12 @@ class NumericSearch: # {{{
dt = datatype
if is_many and query in {'true', 'false'}:
def valcheck(x):
return True
if datatype == 'rating':
def valcheck(x):
return (x is not None and x > 0)
else:
def valcheck(x):
return True
found = set()
for val, book_ids in field_iter():
if valcheck(val):
@ -273,6 +274,7 @@ class NumericSearch: # {{{
if dt == 'rating':
def cast(x):
return (0 if x is None else int(x))
def adjust(x):
return (x // 2)
else:

View File

@ -57,8 +57,6 @@ def run_funcs(self, db, ndb, funcs):
if callable(meth):
meth(*args)
else:
def fmt(x):
return x
if meth[0] in {'!', '@', '#', '+', '$', '-', '%'}:
if meth[0] != '+':
fmt = {'!':dict, '@':lambda x:frozenset(x or ()), '#':lambda x:set((x or '').split(',')),
@ -68,6 +66,9 @@ def run_funcs(self, db, ndb, funcs):
fmt = args[-1]
args = args[:-1]
meth = meth[1:]
else:
def fmt(x):
return x
res1, res2 = fmt(getattr(db, meth)(*args)), fmt(getattr(ndb, meth)(*args))
self.assertEqual(res1, res2, f'The method: {meth}() returned different results for argument {args}')
# }}}
@ -257,14 +258,15 @@ class LegacyTest(BaseTest):
'books_in_series_of':[(0,), (1,), (2,)],
'books_with_same_title':[(Metadata(db.title(0)),), (Metadata(db.title(1)),), (Metadata('1234'),)],
}):
def fmt(x):
return x
if meth[0] in {'!', '@'}:
fmt = {'!':dict, '@':frozenset}[meth[0]]
meth = meth[1:]
elif meth == 'get_authors_with_ids':
def fmt(val):
return {x[0]: tuple(x[1:]) for x in val}
else:
def fmt(x):
return x
for a in args:
self.assertEqual(fmt(getattr(db, meth)(*a)), fmt(getattr(ndb, meth)(*a)),
f'The method: {meth}() returned different results for argument {a}')

View File

@ -612,11 +612,12 @@ class ReadingTest(BaseTest):
self.assertSetEqual(set(mi.custom_field_keys()), set(pmi.custom_field_keys()))
for field in STANDARD_METADATA_FIELDS | {'#series_index'}:
def f(x):
return x
if field == 'formats':
def f(x):
return (x if x is None else tuple(x))
else:
def f(x):
return x
self.assertEqual(f(getattr(mi, field)), f(getattr(pmi, field)),
f'Standard field: {field} not the same for book {book_id}')
self.assertEqual(mi.format_field(field), pmi.format_field(field),

View File

@ -817,7 +817,7 @@ class HTMLConverter:
valign = css['vertical-align']
if valign in ('sup', 'super', 'sub'):
fp['fontsize'] = int(fp['fontsize']) * 5 // 3
valigner = Sub if valign == 'sub' else Sup
valigner = Sub if valign == 'sub' else Sup # noqa
normal_font_size = int(fp['fontsize'])
if variant == 'small-caps':

View File

@ -181,8 +181,6 @@ class ResultsModel(QAbstractTableModel): # {{{
return None
def sort(self, col, order=Qt.SortOrder.AscendingOrder):
def key(x):
return x
if col == 0:
key = attrgetter('gui_rank')
elif col == 1:
@ -199,6 +197,9 @@ class ResultsModel(QAbstractTableModel): # {{{
elif key == 4:
def key(x):
return bool(x.comments)
else:
def key(x):
return x
self.beginResetModel()
self.results.sort(key=key, reverse=order==Qt.SortOrder.AscendingOrder)

View File

@ -1973,6 +1973,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
icon_map[category] = icon
datatype = cat['datatype']
def avgr(x):
return (0.0 if x.rc == 0 else x.rt / x.rc)
# Duplicate the build of items below to avoid using a lambda func
@ -1980,7 +1981,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
if datatype == 'rating':
def formatter(x):
return ('' * int(x // 2))
def avgr(x):
def avgr(x): # noqa
return x.n
# eliminate the zero ratings line as well as count == 0
items = [v for v in tcategories[category].values() if v.c > 0 and v.n != 0]