From cc172a2a48ae797a849ed892d6484c0685a5bb94 Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Fri, 24 Jan 2025 11:14:18 +0100 Subject: [PATCH] unnecessary map (auto-fix) ruff 'C417' --unsafe-fixes --- ruff-strict-pep8.toml | 2 +- setup/__init__.py | 4 ++-- src/calibre/db/categories.py | 2 +- src/calibre/db/cli/cmd_list.py | 4 ++-- src/calibre/db/cli/cmd_list_categories.py | 6 +++--- src/calibre/db/tests/base.py | 2 +- src/calibre/devices/kindle/apnx_page_generator/pages.py | 4 ++-- src/calibre/ebooks/conversion/plugins/epub_output.py | 2 +- src/calibre/ebooks/metadata/opf2.py | 9 ++++----- src/calibre/ebooks/metadata/xmp.py | 2 +- src/calibre/ebooks/mobi/utils.py | 2 +- src/calibre/ebooks/pdb/haodoo/reader.py | 8 ++------ src/calibre/ebooks/pdf/render/gradients.py | 2 +- src/calibre/gui2/dialogs/metadata_bulk.py | 6 ++---- src/calibre/gui2/dialogs/search.py | 3 +-- src/calibre/gui2/dialogs/template_dialog_code_widget.py | 2 +- src/calibre/gui2/preferences/columns.py | 4 +--- src/calibre/gui2/preferences/create_custom_column.py | 3 +-- src/calibre/gui2/preferences/look_feel.py | 2 +- src/calibre/gui2/preferences/texture_chooser.py | 2 +- src/calibre/gui2/search_box.py | 4 +--- .../gui2/store/config/chooser/adv_search_builder.py | 3 +-- src/calibre/gui2/store/search/adv_search_builder.py | 3 +-- .../gui2/store/stores/mobileread/adv_search_builder.py | 3 +-- src/calibre/gui2/tweak_book/diff/view.py | 2 +- src/calibre/gui2/tweak_book/editor/text.py | 2 +- src/calibre/library/database2.py | 2 +- src/calibre/srv/http_response.py | 2 +- src/calibre/srv/tests/auth.py | 2 +- src/calibre/srv/tests/loop.py | 2 +- src/calibre/srv/users.py | 4 ++-- src/calibre/test_build.py | 2 +- src/calibre/utils/matcher.py | 2 +- 33 files changed, 44 insertions(+), 60 deletions(-) diff --git a/ruff-strict-pep8.toml b/ruff-strict-pep8.toml index 54eec4a104..fb6af8e1e9 100644 --- a/ruff-strict-pep8.toml +++ b/ruff-strict-pep8.toml @@ -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', diff --git a/setup/__init__.py b/setup/__init__.py index d43f1e8dd4..2ced671aa4 100644 --- a/setup/__init__.py +++ b/setup/__init__.py @@ -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 diff --git a/src/calibre/db/categories.py b/src/calibre/db/categories.py index fe25e70641..19ebb2994f 100644 --- a/src/calibre/db/categories.py +++ b/src/calibre/db/categories.py @@ -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): diff --git a/src/calibre/db/cli/cmd_list.py b/src/calibre/db/cli/cmd_list.py index cbb62578f4..a030c20bb6 100644 --- a/src/calibre/db/cli/cmd_list.py +++ b/src/calibre/db/cli/cmd_list.py @@ -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 diff --git a/src/calibre/db/cli/cmd_list_categories.py b/src/calibre/db/cli/cmd_list_categories.py index a0f3df64ad..b474beaed2 100644 --- a/src/calibre/db/cli/cmd_list_categories.py +++ b/src/calibre/db/cli/cmd_list_categories.py @@ -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 = [ diff --git a/src/calibre/db/tests/base.py b/src/calibre/db/tests/base.py index 26df5522e6..6af4ec2510 100644 --- a/src/calibre/db/tests/base.py +++ b/src/calibre/db/tests/base.py @@ -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, diff --git a/src/calibre/devices/kindle/apnx_page_generator/pages.py b/src/calibre/devices/kindle/apnx_page_generator/pages.py index 6960c856f4..9c92bf4637 100644 --- a/src/calibre/devices/kindle/apnx_page_generator/pages.py +++ b/src/calibre/devices/kindle/apnx_page_generator/pages.py @@ -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]) diff --git a/src/calibre/ebooks/conversion/plugins/epub_output.py b/src/calibre/ebooks/conversion/plugins/epub_output.py index 4662569008..6a41d42858 100644 --- a/src/calibre/ebooks/conversion/plugins/epub_output.py +++ b/src/calibre/ebooks/conversion/plugins/epub_output.py @@ -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
we replaced) # then this
replacement should have a 1-line height. diff --git a/src/calibre/ebooks/metadata/opf2.py b/src/calibre/ebooks/metadata/opf2.py index 6232cce9d4..4516fbcae8 100644 --- a/src/calibre/ebooks/metadata/opf2.py +++ b/src/calibre/ebooks/metadata/opf2.py @@ -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): diff --git a/src/calibre/ebooks/metadata/xmp.py b/src/calibre/ebooks/metadata/xmp.py index 1dfabe3194..b2eb7021c9 100644 --- a/src/calibre/ebooks/metadata/xmp.py +++ b/src/calibre/ebooks/metadata/xmp.py @@ -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) diff --git a/src/calibre/ebooks/mobi/utils.py b/src/calibre/ebooks/mobi/utils.py index 59bcc513d1..073d56dc74 100644 --- a/src/calibre/ebooks/mobi/utils.py +++ b/src/calibre/ebooks/mobi/utils.py @@ -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)) diff --git a/src/calibre/ebooks/pdb/haodoo/reader.py b/src/calibre/ebooks/pdb/haodoo/reader.py index 0bbca6a38f..29b7095c8d 100644 --- a/src/calibre/ebooks/pdb/haodoo/reader.py +++ b/src/calibre/ebooks/pdb/haodoo/reader.py @@ -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): diff --git a/src/calibre/ebooks/pdf/render/gradients.py b/src/calibre/ebooks/pdf/render/gradients.py index 6e9c1ae1fa..c042509aa8 100644 --- a/src/calibre/ebooks/pdf/render/gradients.py +++ b/src/calibre/ebooks/pdf/render/gradients.py @@ -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] diff --git a/src/calibre/gui2/dialogs/metadata_bulk.py b/src/calibre/gui2/dialogs/metadata_bulk.py index c44076faf2..1bf8a3c016 100644 --- a/src/calibre/gui2/dialogs/metadata_bulk.py +++ b/src/calibre/gui2/dialogs/metadata_bulk.py @@ -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) diff --git a/src/calibre/gui2/dialogs/search.py b/src/calibre/gui2/dialogs/search.py index 46c69e3412..7dad89f7d2 100644 --- a/src/calibre/gui2/dialogs/search.py +++ b/src/calibre/gui2/dialogs/search.py @@ -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) diff --git a/src/calibre/gui2/dialogs/template_dialog_code_widget.py b/src/calibre/gui2/dialogs/template_dialog_code_widget.py index 196eaab1ee..9a3ec98a58 100644 --- a/src/calibre/gui2/dialogs/template_dialog_code_widget.py +++ b/src/calibre/gui2/dialogs/template_dialog_code_widget.py @@ -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: diff --git a/src/calibre/gui2/preferences/columns.py b/src/calibre/gui2/preferences/columns.py index 0ad9242d38..98a413d15f 100644 --- a/src/calibre/gui2/preferences/columns.py +++ b/src/calibre/gui2/preferences/columns.py @@ -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) diff --git a/src/calibre/gui2/preferences/create_custom_column.py b/src/calibre/gui2/preferences/create_custom_column.py index 6409b099ef..fcee648991 100644 --- a/src/calibre/gui2/preferences/create_custom_column.py +++ b/src/calibre/gui2/preferences/create_custom_column.py @@ -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) diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index 5567ac4aba..acbd7fdddf 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -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: diff --git a/src/calibre/gui2/preferences/texture_chooser.py b/src/calibre/gui2/preferences/texture_chooser.py index a0f1ea55ca..3d04b6d52c 100644 --- a/src/calibre/gui2/preferences/texture_chooser.py +++ b/src/calibre/gui2/preferences/texture_chooser.py @@ -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, diff --git a/src/calibre/gui2/search_box.py b/src/calibre/gui2/search_box.py index 7e03a0a88d..eeeccc6239 100644 --- a/src/calibre/gui2/search_box.py +++ b/src/calibre/gui2/search_box.py @@ -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) diff --git a/src/calibre/gui2/store/config/chooser/adv_search_builder.py b/src/calibre/gui2/store/config/chooser/adv_search_builder.py index ca6129fddf..5a443320e6 100644 --- a/src/calibre/gui2/store/config/chooser/adv_search_builder.py +++ b/src/calibre/gui2/store/config/chooser/adv_search_builder.py @@ -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) diff --git a/src/calibre/gui2/store/search/adv_search_builder.py b/src/calibre/gui2/store/search/adv_search_builder.py index c6442c89ec..91281a6512 100644 --- a/src/calibre/gui2/store/search/adv_search_builder.py +++ b/src/calibre/gui2/store/search/adv_search_builder.py @@ -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) diff --git a/src/calibre/gui2/store/stores/mobileread/adv_search_builder.py b/src/calibre/gui2/store/stores/mobileread/adv_search_builder.py index 8ea8dbea80..2c9781e9ce 100644 --- a/src/calibre/gui2/store/stores/mobileread/adv_search_builder.py +++ b/src/calibre/gui2/store/stores/mobileread/adv_search_builder.py @@ -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) diff --git a/src/calibre/gui2/tweak_book/diff/view.py b/src/calibre/gui2/tweak_book/diff/view.py index d7e487dc76..12e0735604 100644 --- a/src/calibre/gui2/tweak_book/diff/view.py +++ b/src/calibre/gui2/tweak_book/diff/view.py @@ -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): diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index cab778533d..63b7c96a1f 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -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() diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 03925d9d72..bce7e1f990 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -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', {}) diff --git a/src/calibre/srv/http_response.py b/src/calibre/srv/http_response.py index 290e5f06cb..c91e71dc8f 100644 --- a/src/calibre/srv/http_response.py +++ b/src/calibre/srv/http_response.py @@ -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 diff --git a/src/calibre/srv/tests/auth.py b/src/calibre/srv/tests/auth.py index 3580862472..290d537839 100644 --- a/src/calibre/srv/tests/auth.py +++ b/src/calibre/srv/tests/auth.py @@ -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 diff --git a/src/calibre/srv/tests/loop.py b/src/calibre/srv/tests/loop.py index 4a01d7f3b2..773ce382d0 100644 --- a/src/calibre/srv/tests/loop.py +++ b/src/calibre/srv/tests/loop.py @@ -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 diff --git a/src/calibre/srv/users.py b/src/calibre/srv/users.py index 3a5f00e1b1..e10859a1a1 100644 --- a/src/calibre/srv/users.py +++ b/src/calibre/srv/users.py @@ -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 diff --git a/src/calibre/test_build.py b/src/calibre/test_build.py index e403522c37..494cbe9e7b 100644 --- a/src/calibre/test_build.py +++ b/src/calibre/test_build.py @@ -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) diff --git a/src/calibre/utils/matcher.py b/src/calibre/utils/matcher.py index f9300de916..ee85d4a568 100644 --- a/src/calibre/utils/matcher.py +++ b/src/calibre/utils/matcher.py @@ -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]