mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
unnecessary map (auto-fix)
ruff 'C417' --unsafe-fixes
This commit is contained in:
parent
6cda6a2e5d
commit
cc172a2a48
@ -19,7 +19,7 @@ quote-style = 'single'
|
||||
[lint]
|
||||
ignore = [
|
||||
'E402', 'E722', 'E741',
|
||||
'UP012', 'UP030', 'UP032', 'UP038', 'C408', 'C413', 'C417', 'C420',
|
||||
'UP012', 'UP030', 'UP032', 'UP038', 'C408', 'C413', 'C420',
|
||||
]
|
||||
select = [
|
||||
'E', 'F', 'I', 'W', 'INT',
|
||||
|
@ -46,10 +46,10 @@ def newer(targets, sources):
|
||||
for f in targets:
|
||||
if not os.path.exists(f):
|
||||
return True
|
||||
ttimes = map(lambda x: os.stat(x).st_mtime, targets)
|
||||
ttimes = (os.stat(x).st_mtime for x in targets)
|
||||
oldest_target = min(ttimes)
|
||||
try:
|
||||
stimes = map(lambda x: os.stat(x).st_mtime, sources)
|
||||
stimes = (os.stat(x).st_mtime for x in sources)
|
||||
newest_source = max(stimes)
|
||||
except FileNotFoundError:
|
||||
newest_source = oldest_target +1
|
||||
|
@ -279,7 +279,7 @@ def get_categories(dbcache, sort='name', book_ids=None, first_letter_sort=False,
|
||||
# temporarily duplicating the categories lists.
|
||||
taglist = {}
|
||||
for c, items in iteritems(categories):
|
||||
taglist[c] = dict(map(lambda t:(icu_lower(t.name), t), items))
|
||||
taglist[c] = {icu_lower(t.name): t for t in items}
|
||||
|
||||
# Add the category values to the user categories
|
||||
for user_cat in sorted(user_categories, key=sort_key):
|
||||
|
@ -205,7 +205,7 @@ def do_list(
|
||||
from calibre.utils.terminal import ColoredStream, geometry
|
||||
|
||||
output_table = prepare_output_table(fields, book_ids, data, metadata)
|
||||
widths = list(map(lambda x: 0, fields))
|
||||
widths = [0 for x in fields]
|
||||
|
||||
for record in output_table:
|
||||
for j in range(len(fields)):
|
||||
@ -215,7 +215,7 @@ def do_list(
|
||||
if not screen_width:
|
||||
screen_width = 80
|
||||
field_width = screen_width // len(fields)
|
||||
base_widths = list(map(lambda x: min(x + 1, field_width), widths))
|
||||
base_widths = [min(x + 1, field_width) for x in widths]
|
||||
|
||||
while sum(base_widths) < screen_width:
|
||||
adjusted = False
|
||||
|
@ -74,7 +74,7 @@ def do_list(fields, data, opts):
|
||||
from calibre.utils.terminal import ColoredStream, geometry
|
||||
|
||||
separator = ' '
|
||||
widths = list(map(lambda x: 0, fields))
|
||||
widths = [0 for x in fields]
|
||||
for i in data:
|
||||
for j, field in enumerate(fields):
|
||||
widths[j] = max(widths[j], max(len(field), len(str(i[field]))))
|
||||
@ -83,7 +83,7 @@ def do_list(fields, data, opts):
|
||||
if not screen_width:
|
||||
screen_width = 80
|
||||
field_width = screen_width // len(fields)
|
||||
base_widths = list(map(lambda x: min(x + 1, field_width), widths))
|
||||
base_widths = [min(x + 1, field_width) for x in widths]
|
||||
|
||||
while sum(base_widths) < screen_width:
|
||||
adjusted = False
|
||||
@ -104,7 +104,7 @@ def do_list(fields, data, opts):
|
||||
with ColoredStream(sys.stdout, fg='green'):
|
||||
prints(''.join(titles))
|
||||
|
||||
wrappers = list(map(lambda x: TextWrapper(x - 1), widths))
|
||||
wrappers = [TextWrapper(x - 1) for x in widths]
|
||||
|
||||
for record in data:
|
||||
text = [
|
||||
|
@ -110,7 +110,7 @@ class BaseTest(unittest.TestCase):
|
||||
continue
|
||||
attr1, attr2 = getattr(mi1, attr), getattr(mi2, attr)
|
||||
if attr == 'formats':
|
||||
attr1, attr2 = map(lambda x:tuple(x) if x else (), (attr1, attr2))
|
||||
attr1, attr2 = (tuple(x) if x else () for x in (attr1, attr2))
|
||||
if isinstance(attr1, (tuple, list)) and 'authors' not in attr and 'languages' not in attr:
|
||||
attr1, attr2 = set(attr1), set(attr2)
|
||||
self.assertEqual(attr1, attr2,
|
||||
|
@ -34,10 +34,10 @@ class Pages:
|
||||
|
||||
@property
|
||||
def page_locations(self) -> list[int]:
|
||||
return list(itertools.chain.from_iterable(list(map(lambda pg: pg.page_locations, self.__pages_groups))))
|
||||
return list(itertools.chain.from_iterable([pg.page_locations for pg in self.__pages_groups]))
|
||||
|
||||
@property
|
||||
def number_of_pages(self) -> int:
|
||||
return sum(list(map(lambda pg: len(pg.page_locations), self.__pages_groups)))
|
||||
return sum([len(pg.page_locations) for pg in self.__pages_groups])
|
||||
|
||||
|
||||
|
@ -452,7 +452,7 @@ class EPUBOutput(OutputFormatPlugin):
|
||||
br.tag = XHTML('p')
|
||||
br.text = '\u00a0'
|
||||
style = br.get('style', '').split(';')
|
||||
style = list(filter(None, map(lambda x: x.strip(), style)))
|
||||
style = list(filter(None, (x.strip() for x in style)))
|
||||
style.append('margin:0pt; border:0pt')
|
||||
# If the prior tag is a block (including a <br> we replaced)
|
||||
# then this <br> replacement should have a 1-line height.
|
||||
|
@ -1432,9 +1432,8 @@ class OPFCreator(Metadata):
|
||||
|
||||
`entries`: List of (path, mime-type) If mime-type is None it is autodetected
|
||||
'''
|
||||
entries = list(map(lambda x: x if os.path.isabs(x[0]) else
|
||||
(os.path.abspath(os.path.join(self.base_path, x[0])), x[1]),
|
||||
entries))
|
||||
entries = [x if os.path.isabs(x[0]) else
|
||||
(os.path.abspath(os.path.join(self.base_path, x[0])), x[1]) for x in entries]
|
||||
self.manifest = Manifest.from_paths(entries)
|
||||
self.manifest.set_basedir(self.base_path)
|
||||
|
||||
@ -1464,8 +1463,8 @@ class OPFCreator(Metadata):
|
||||
|
||||
`entries`: List of paths
|
||||
'''
|
||||
entries = list(map(lambda x: x if os.path.isabs(x) else
|
||||
os.path.abspath(os.path.join(self.base_path, x)), entries))
|
||||
entries = [x if os.path.isabs(x) else
|
||||
os.path.abspath(os.path.join(self.base_path, x)) for x in entries]
|
||||
self.spine = Spine.from_paths(entries, self.manifest)
|
||||
|
||||
def set_toc(self, toc):
|
||||
|
@ -495,7 +495,7 @@ def metadata_to_xmp_packet(mi):
|
||||
if not mi.is_null('pubdate'):
|
||||
create_sequence_property(dc, 'dc:date', [isoformat(mi.pubdate, as_utc=False)]) # Adobe spec recommends local time
|
||||
if not mi.is_null('languages'):
|
||||
langs = list(filter(None, map(lambda x:lang_as_iso639_1(x) or canonicalize_lang(x), mi.languages)))
|
||||
langs = list(filter(None, (lang_as_iso639_1(x) or canonicalize_lang(x) for x in mi.languages)))
|
||||
if langs:
|
||||
create_sequence_property(dc, 'dc:language', langs, ordered=False)
|
||||
|
||||
|
@ -647,4 +647,4 @@ def convert_color_for_font_tag(val):
|
||||
def clamp(x):
|
||||
return min(x, max(0, x), 1)
|
||||
rgb = map(clamp, rgba[:3])
|
||||
return '#' + ''.join(map(lambda x:'%02x' % int(x * 255), rgb))
|
||||
return '#' + ''.join(('%02x' % int(x * 255) for x in rgb))
|
||||
|
@ -60,9 +60,7 @@ class LegacyHeaderRecord:
|
||||
fields = raw.lstrip().replace(b'\x1b\x1b\x1b', b'\x1b').split(b'\x1b')
|
||||
self.title = fix_punct(fields[0].decode('cp950', 'replace'))
|
||||
self.num_records = int(fields[1])
|
||||
self.chapter_titles = list(map(
|
||||
lambda x: fix_punct(x.decode('cp950', 'replace').rstrip('\x00')),
|
||||
fields[2:]))
|
||||
self.chapter_titles = [fix_punct(x.decode('cp950', 'replace').rstrip('\x00')) for x in fields[2:]]
|
||||
|
||||
|
||||
class UnicodeHeaderRecord:
|
||||
@ -72,9 +70,7 @@ class UnicodeHeaderRecord:
|
||||
b'\x1b\x00').split(b'\x1b\x00')
|
||||
self.title = fix_punct(fields[0].decode('utf_16_le', 'ignore'))
|
||||
self.num_records = int(fields[1])
|
||||
self.chapter_titles = list(map(
|
||||
lambda x: fix_punct(x.decode('utf_16_le', 'replace').rstrip('\x00')),
|
||||
fields[2].split(b'\r\x00\n\x00')))
|
||||
self.chapter_titles = [fix_punct(x.decode('utf_16_le', 'replace').rstrip('\x00')) for x in fields[2].split(b'\r\x00\n\x00')]
|
||||
|
||||
|
||||
class Reader(FormatReader):
|
||||
|
@ -79,7 +79,7 @@ class LinearGradientPattern(Dictionary):
|
||||
matrix):
|
||||
start = gradient.start()
|
||||
stop = gradient.finalStop()
|
||||
stops = list(map(lambda x: [x[0], x[1].getRgbF()], gradient.stops()))
|
||||
stops = [[x[0], x[1].getRgbF()] for x in gradient.stops()]
|
||||
spread = gradient.spread()
|
||||
if spread != gradient.PadSpread:
|
||||
inv = matrix.inverted()[0]
|
||||
|
@ -660,10 +660,8 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
||||
self.button_transform_publishers.clicked.connect(self.transform_publishers)
|
||||
self.button_transform_series.clicked.connect(self.transform_series)
|
||||
self.tag_map_rules = self.author_map_rules = self.publisher_map_rules = self.series_map_rules = ()
|
||||
tuple(map(lambda b: (b.clicked.connect(self.clear_transform_rules_for), b.setIcon(QIcon.ic('clear_left.png')), b.setToolTip(_(
|
||||
'Clear the rules'))),
|
||||
(self.button_clear_tags_rules, self.button_clear_authors_rules, self.button_clear_publishers_rules)
|
||||
))
|
||||
tuple(((b.clicked.connect(self.clear_transform_rules_for), b.setIcon(QIcon.ic('clear_left.png')), b.setToolTip(_(
|
||||
'Clear the rules'))) for b in (self.button_clear_tags_rules, self.button_clear_authors_rules, self.button_clear_publishers_rules)))
|
||||
self.update_transform_labels()
|
||||
if starting_tab < 0:
|
||||
starting_tab = gprefs.get('bulk_metadata_window_tab', 0)
|
||||
|
@ -505,8 +505,7 @@ class SearchDialog(QDialog):
|
||||
self.mc = '~'
|
||||
else:
|
||||
self.mc = '^'
|
||||
all, any, phrase, none = map(lambda x: str(x.text()),
|
||||
(self.all, self.any, self.phrase, self.none))
|
||||
all, any, phrase, none = (str(x.text()) for x in (self.all, self.any, self.phrase, self.none))
|
||||
all, any, none = map(self.tokens, (all, any, none))
|
||||
phrase = phrase.strip()
|
||||
all = ' and '.join(all)
|
||||
|
@ -59,7 +59,7 @@ class CodeEditor(QPlainTextEdit):
|
||||
def line_number_area_width(self):
|
||||
# get largest width of digits
|
||||
fm = self.fontMetrics()
|
||||
self.number_width = max(map(lambda x:fm.horizontalAdvance(str(x)), range(10)))
|
||||
self.number_width = max((fm.horizontalAdvance(str(x)) for x in range(10)))
|
||||
digits = 1
|
||||
limit = max(1, self.blockCount())
|
||||
while limit >= 10:
|
||||
|
@ -107,9 +107,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
self.opt_columns.verticalHeader().hide()
|
||||
|
||||
self.opt_columns.setRowCount(len(colmap))
|
||||
self.column_desc = dict(map(lambda x:(CreateCustomColumn.column_types[x]['datatype'],
|
||||
CreateCustomColumn.column_types[x]['text']),
|
||||
CreateCustomColumn.column_types))
|
||||
self.column_desc = {CreateCustomColumn.column_types[x]['datatype']: CreateCustomColumn.column_types[x]['text'] for x in CreateCustomColumn.column_types}
|
||||
|
||||
for row, key in enumerate(colmap):
|
||||
self.setup_row(row, key, row)
|
||||
|
@ -157,8 +157,7 @@ class CreateCustomColumn(QDialog):
|
||||
ct = '*' + ct
|
||||
self.orig_column_number = c['colnum']
|
||||
self.orig_column_name = col
|
||||
column_numbers = dict(map(lambda x:(self.column_types[x]['datatype'], x),
|
||||
self.column_types))
|
||||
column_numbers = {self.column_types[x]['datatype']: x for x in self.column_types}
|
||||
self.column_type_box.setCurrentIndex(column_numbers[ct])
|
||||
self.column_type_box.setEnabled(False)
|
||||
|
||||
|
@ -236,7 +236,7 @@ class IdLinksEditor(Dialog):
|
||||
def edit_rule(self, r=-1):
|
||||
key = name = template = ''
|
||||
if r > -1:
|
||||
key, name, template = map(lambda c: self.table.item(r, c).text(), range(3))
|
||||
key, name, template = (self.table.item(r, c).text() for c in range(3))
|
||||
d = IdLinksRuleEdit(key, name, template, self)
|
||||
if d.exec() == QDialog.DialogCode.Accepted:
|
||||
if r < 0:
|
||||
|
@ -86,7 +86,7 @@ class TextureChooser(QDialog):
|
||||
images = [{
|
||||
'fname': ':'+os.path.basename(x),
|
||||
'path': x,
|
||||
'name': ' '.join(map(lambda s: s.capitalize(), os.path.splitext(os.path.basename(x))[0].split('_')))
|
||||
'name': ' '.join((s.capitalize() for s in os.path.splitext(os.path.basename(x))[0].split('_')))
|
||||
} for x in glob.glob(I('textures/*.png'))] + [{
|
||||
'fname': os.path.basename(x),
|
||||
'path': x,
|
||||
|
@ -363,9 +363,7 @@ class SearchBoxMixin: # {{{
|
||||
self.search.clear()
|
||||
self.search.setMaximumWidth(self.width()-150)
|
||||
self.action_focus_search = QAction(self)
|
||||
shortcuts = list(
|
||||
map(lambda x:str(x.toString(QKeySequence.SequenceFormat.PortableText)),
|
||||
QKeySequence.keyBindings(QKeySequence.StandardKey.Find)))
|
||||
shortcuts = [str(x.toString(QKeySequence.SequenceFormat.PortableText)) for x in QKeySequence.keyBindings(QKeySequence.StandardKey.Find)]
|
||||
shortcuts += ['/', 'Alt+S']
|
||||
self.keyboard.register_shortcut('start search', _('Start search'),
|
||||
default_keys=shortcuts, action=self.action_focus_search)
|
||||
|
@ -73,8 +73,7 @@ class AdvSearchBuilderDialog(QDialog, Ui_Dialog):
|
||||
self.mc = '='
|
||||
else:
|
||||
self.mc = '~'
|
||||
all, any, phrase, none = map(lambda x: str(x.text()),
|
||||
(self.all, self.any, self.phrase, self.none))
|
||||
all, any, phrase, none = (str(x.text()) for x in (self.all, self.any, self.phrase, self.none))
|
||||
all, any, none = map(self.tokens, (all, any, none))
|
||||
phrase = phrase.strip()
|
||||
all = ' and '.join(all)
|
||||
|
@ -80,8 +80,7 @@ class AdvSearchBuilderDialog(QDialog, Ui_Dialog):
|
||||
self.mc = '='
|
||||
else:
|
||||
self.mc = '~'
|
||||
all, any, phrase, none = list(map(lambda x: str(x.text()),
|
||||
(self.all, self.any, self.phrase, self.none)))
|
||||
all, any, phrase, none = [str(x.text()) for x in (self.all, self.any, self.phrase, self.none)]
|
||||
all, any, none = list(map(self.tokens, (all, any, none)))
|
||||
phrase = phrase.strip()
|
||||
all = ' and '.join(all)
|
||||
|
@ -73,8 +73,7 @@ class AdvSearchBuilderDialog(QDialog, Ui_Dialog):
|
||||
self.mc = '='
|
||||
else:
|
||||
self.mc = '~'
|
||||
all, any, phrase, none = list(map(lambda x: type(u'')(x.text()),
|
||||
(self.all, self.any, self.phrase, self.none)))
|
||||
all, any, phrase, none = [type(u'')(x.text()) for x in (self.all, self.any, self.phrase, self.none)]
|
||||
all, any, none = list(map(self.tokens, (all, any, none)))
|
||||
phrase = phrase.strip()
|
||||
all = ' and '.join(all)
|
||||
|
@ -181,7 +181,7 @@ class TextBrowser(PlainTextEdit): # {{{
|
||||
|
||||
def calculate_metrics(self):
|
||||
fm = self.fontMetrics()
|
||||
self.number_width = max(map(lambda x:fm.horizontalAdvance(str(x)), range(10)))
|
||||
self.number_width = max((fm.horizontalAdvance(str(x)) for x in range(10)))
|
||||
self.space_width = fm.horizontalAdvance(' ')
|
||||
|
||||
def show_context_menu(self, pos):
|
||||
|
@ -282,7 +282,7 @@ class TextEdit(PlainTextEdit):
|
||||
self.setFont(font)
|
||||
self.highlighter.apply_theme(theme)
|
||||
fm = self.fontMetrics()
|
||||
self.number_width = max(map(lambda x:fm.horizontalAdvance(str(x)), range(10)))
|
||||
self.number_width = max((fm.horizontalAdvance(str(x)) for x in range(10)))
|
||||
self.size_hint = QSize(self.expected_geometry[0] * fm.averageCharWidth(), self.expected_geometry[1] * fm.height())
|
||||
self.highlight_color = theme_color(theme, 'HighlightRegion', 'bg')
|
||||
self.highlight_cursor_line()
|
||||
|
@ -2119,7 +2119,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
||||
# temporarily duplicating the categories lists.
|
||||
taglist = {}
|
||||
for c in categories.keys():
|
||||
taglist[c] = dict(map(lambda t:(icu_lower(t.name), t), categories[c]))
|
||||
taglist[c] = {icu_lower(t.name): t for t in categories[c]}
|
||||
|
||||
muc = self.prefs.get('grouped_search_make_user_categories', [])
|
||||
gst = self.prefs.get('grouped_search_terms', {})
|
||||
|
@ -69,7 +69,7 @@ def parse_multipart_byterange(buf, content_type): # {{{
|
||||
if not cr.startswith('bytes '):
|
||||
raise ValueError('Malformed Content-Range header in sub-part, no prefix')
|
||||
try:
|
||||
start, stop = map(lambda x: int(x.strip()), cr.partition(' ')[-1].partition('/')[0].partition('-')[::2])
|
||||
start, stop = (int(x.strip()) for x in cr.partition(' ')[-1].partition('/')[0].partition('-')[::2])
|
||||
except Exception:
|
||||
raise ValueError('Malformed Content-Range header in sub-part, failed to parse byte range')
|
||||
content_length = stop - start + 1
|
||||
|
@ -131,7 +131,7 @@ class TestAuth(BaseTest):
|
||||
opts = Options(userdb=':memory:')
|
||||
Data = namedtuple('Data', 'username')
|
||||
with TemporaryDirectory() as base:
|
||||
l1, l2, l3 = map(lambda x: os.path.join(base, 'l' + x), '123')
|
||||
l1, l2, l3 = (os.path.join(base, 'l' + x) for x in '123')
|
||||
for l in (l1, l2, l3):
|
||||
create_backend(l).close()
|
||||
ctx = Handler((l1, l2, l3), opts).router.ctx
|
||||
|
@ -198,7 +198,7 @@ class LoopTest(BaseTest):
|
||||
'Test serving over SSL'
|
||||
address = '127.0.0.1'
|
||||
with TemporaryDirectory('srv-test-ssl') as tdir:
|
||||
cert_file, key_file, ca_file = map(lambda x:os.path.join(tdir, x), 'cka')
|
||||
cert_file, key_file, ca_file = (os.path.join(tdir, x) for x in 'cka')
|
||||
create_server_cert(address, ca_file, cert_file, key_file, key_size=2048)
|
||||
ctx = ssl.create_default_context(cafile=ca_file)
|
||||
ctx.verify_flags |= ssl.VERIFY_X509_STRICT
|
||||
|
@ -36,8 +36,8 @@ def parse_restriction(raw):
|
||||
lr = r.get('library_restrictions', {})
|
||||
if not isinstance(lr, dict):
|
||||
lr = {}
|
||||
r['allowed_library_names'] = frozenset(map(lambda x: x.lower(), r.get('allowed_library_names', ())))
|
||||
r['blocked_library_names'] = frozenset(map(lambda x: x.lower(), r.get('blocked_library_names', ())))
|
||||
r['allowed_library_names'] = frozenset((x.lower() for x in r.get('allowed_library_names', ())))
|
||||
r['blocked_library_names'] = frozenset((x.lower() for x in r.get('blocked_library_names', ())))
|
||||
r['library_restrictions'] = {k.lower(): v or '' for k, v in iteritems(lr)}
|
||||
return r
|
||||
|
||||
|
@ -344,7 +344,7 @@ class BuildTest(unittest.TestCase):
|
||||
# package. On non-frozen builds, it should just work because the
|
||||
# hard-coded paths of the Qt installation should work. If they do not,
|
||||
# then it is a distro problem.
|
||||
fmts = set(map(lambda x: x.data().decode('utf-8'), QImageReader.supportedImageFormats())) # no2to3
|
||||
fmts = {x.data().decode('utf-8') for x in QImageReader.supportedImageFormats()} # no2to3
|
||||
testf = {'jpg', 'png', 'svg', 'ico', 'gif', 'webp'}
|
||||
self.assertEqual(testf.intersection(fmts), testf, "Qt doesn't seem to be able to load some of its image plugins. Available plugins: %s" % fmts)
|
||||
data = P('images/blank.png', allow_user_override=False, data=True)
|
||||
|
@ -99,7 +99,7 @@ class Matcher:
|
||||
w = [Worker(requests, results) for i in range(max(1, cpu_count()))]
|
||||
[x.start() for x in w]
|
||||
workers.extend(w)
|
||||
items = map(lambda x: normalize('NFC', str(x)), filter(None, items))
|
||||
items = (normalize('NFC', str(x)) for x in filter(None, items))
|
||||
self.items = items = tuple(items)
|
||||
tasks = split(items, len(workers))
|
||||
self.task_maps = [{j: i for j, (i, _) in enumerate(task)} for task in tasks]
|
||||
|
Loading…
x
Reference in New Issue
Block a user