From 76c091c975465421246e28f4ed36aad895db0514 Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Fri, 24 Jan 2025 11:14:19 +0100 Subject: [PATCH] parenthesize chained operators (auto-fix) ruff 'RUF021' --- ruff-strict-pep8.toml | 2 +- src/calibre/db/cli/cmd_add.py | 2 +- src/calibre/db/restore.py | 2 +- src/calibre/devices/kobo/driver.py | 6 +++--- src/calibre/ebooks/metadata/mobi.py | 2 +- src/calibre/ebooks/metadata/topaz.py | 2 +- src/calibre/ebooks/oeb/iterator/book.py | 4 ++-- src/calibre/ebooks/oeb/transforms/page_margin.py | 2 +- src/calibre/gui2/book_details.py | 2 +- src/calibre/gui2/central.py | 2 +- src/calibre/gui2/dnd.py | 2 +- src/calibre/gui2/tag_browser/model.py | 4 ++-- src/calibre/library/restore.py | 2 +- src/calibre/utils/magick/legacy.py | 2 +- src/calibre/utils/mem.py | 2 +- 15 files changed, 19 insertions(+), 19 deletions(-) diff --git a/ruff-strict-pep8.toml b/ruff-strict-pep8.toml index 4d78f5048e..3e26e03f61 100644 --- a/ruff-strict-pep8.toml +++ b/ruff-strict-pep8.toml @@ -20,7 +20,7 @@ quote-style = 'single' ignore = [ 'E402', 'E722', 'E741', 'UP012', 'UP030', 'UP032', 'UP038', 'C413', 'C420', - 'RUF001', 'RUF002', 'RUF003', 'RUF005', 'RUF010', 'RUF012', 'RUF013', 'RUF015', 'RUF021', 'RUF031', 'RUF034', 'RUF100', + 'RUF001', 'RUF002', 'RUF003', 'RUF005', 'RUF010', 'RUF012', 'RUF013', 'RUF015', 'RUF031', 'RUF034', 'RUF100', ] select = [ 'E', 'F', 'I', 'W', 'INT', diff --git a/src/calibre/db/cli/cmd_add.py b/src/calibre/db/cli/cmd_add.py index dd527d63ae..7e8b9e60d9 100644 --- a/src/calibre/db/cli/cmd_add.py +++ b/src/calibre/db/cli/cmd_add.py @@ -163,7 +163,7 @@ def format_group(db, notify_changes, is_remote, args): mi = metadata_from_formats(paths) if mi.title is None: return None, set(), set(), False - if cover_data and not mi.cover_data or not mi.cover_data[1]: + if (cover_data and not mi.cover_data) or not mi.cover_data[1]: mi.cover_data = 'jpeg', cover_data format_map = create_format_map(paths) added_ids, updated_ids, duplicates = do_adding( diff --git a/src/calibre/db/restore.py b/src/calibre/db/restore.py index 7a5da13232..8c2cb76054 100644 --- a/src/calibre/db/restore.py +++ b/src/calibre/db/restore.py @@ -253,7 +253,7 @@ class Restore(Thread): dest = self.link_maps.setdefault(field, {}) for item, link in lmap.items(): existing_link, timestamp = dest.get(item, (None, None)) - if existing_link is None or existing_link != link and timestamp < mi.timestamp: + if existing_link is None or (existing_link != link and timestamp < mi.timestamp): dest[item] = link, mi.timestamp def create_cc_metadata(self): diff --git a/src/calibre/devices/kobo/driver.py b/src/calibre/devices/kobo/driver.py index 0d5fe8a183..04ddb8d84e 100644 --- a/src/calibre/devices/kobo/driver.py +++ b/src/calibre/devices/kobo/driver.py @@ -1782,7 +1782,7 @@ class KOBOTOUCH(KOBO): # - FW2.1.2 beta, DBVersion == 56, accessibility == -1: # So, the following should be OK if self.is_false_value(isdownloaded): - if self.dbversion < 56 and accessibility <= 1 or self.dbversion >= 56 and accessibility == -1: + if (self.dbversion < 56 and accessibility <= 1) or (self.dbversion >= 56 and accessibility == -1): playlist_map[lpath].append('Deleted') allow_shelves = False if show_debug: @@ -2689,7 +2689,7 @@ class KOBOTOUCH(KOBO): self.reset_favouritesindex(connection, oncard) # Set the series info and cleanup the bookshelves only if the firmware supports them and the user has set the options. - if (self.supports_bookshelves and self.manage_collections or self.supports_series()) and ( + if ((self.supports_bookshelves and self.manage_collections) or self.supports_series()) and ( have_bookshelf_attributes or update_series_details or update_core_metadata): debug_print('KoboTouch:update_device_database_collections - managing bookshelves and series.') @@ -4204,7 +4204,7 @@ class KOBOTOUCH(KOBO): if not self.debugging_title and not self.debugging_title == '': self.debugging_title = self.get_debugging_title() try: - is_debugging = len(self.debugging_title) > 0 and title.lower().find(self.debugging_title.lower()) >= 0 or len(title) == 0 + is_debugging = (len(self.debugging_title) > 0 and title.lower().find(self.debugging_title.lower()) >= 0) or len(title) == 0 except: debug_print(("KoboTouch::is_debugging_title - Exception checking debugging title for title '{}'.").format(title)) is_debugging = False diff --git a/src/calibre/ebooks/metadata/mobi.py b/src/calibre/ebooks/metadata/mobi.py index d651b167a1..3eba193b34 100644 --- a/src/calibre/ebooks/metadata/mobi.py +++ b/src/calibre/ebooks/metadata/mobi.py @@ -279,7 +279,7 @@ class MetadataUpdater: def hexdump(self, src, length=16): # Diagnostic - FILTER=''.join([(len(repr(codepoint_to_chr(x)))==3) and codepoint_to_chr(x) or '.' for x in range(256)]) + FILTER=''.join([((len(repr(codepoint_to_chr(x)))==3) and codepoint_to_chr(x)) or '.' for x in range(256)]) N=0 result='' while src: diff --git a/src/calibre/ebooks/metadata/topaz.py b/src/calibre/ebooks/metadata/topaz.py index d82df6cc94..54106e7cfe 100644 --- a/src/calibre/ebooks/metadata/topaz.py +++ b/src/calibre/ebooks/metadata/topaz.py @@ -154,7 +154,7 @@ class MetadataUpdater: def dump_hex(self, src, length=16): ''' Diagnostic ''' - FILTER=''.join([(len(repr(codepoint_to_chr(x)))==3) and codepoint_to_chr(x) or '.' for x in range(256)]) + FILTER=''.join([((len(repr(codepoint_to_chr(x)))==3) and codepoint_to_chr(x)) or '.' for x in range(256)]) N=0 result='' while src: diff --git a/src/calibre/ebooks/oeb/iterator/book.py b/src/calibre/ebooks/oeb/iterator/book.py index efb594f43d..9dce2c9561 100644 --- a/src/calibre/ebooks/oeb/iterator/book.py +++ b/src/calibre/ebooks/oeb/iterator/book.py @@ -67,8 +67,8 @@ def extract_book(pathtoebook, tdir, log=None, view_kepub=False, processed=False, if not only_input_plugin: # Run the HTML preprocess/parsing from the conversion pipeline as # well - if (processed or plumber.input_fmt.lower() in {'pdb', 'pdf', 'rb'} and - not hasattr(pathtoopf, 'manifest')): + if (processed or (plumber.input_fmt.lower() in {'pdb', 'pdf', 'rb'} and + not hasattr(pathtoopf, 'manifest'))): if hasattr(pathtoopf, 'manifest'): pathtoopf = write_oebbook(pathtoopf, tdir) pathtoopf = create_oebbook(log, pathtoopf, plumber.opts) diff --git a/src/calibre/ebooks/oeb/transforms/page_margin.py b/src/calibre/ebooks/oeb/transforms/page_margin.py index 7b49788e15..46906a5847 100644 --- a/src/calibre/ebooks/oeb/transforms/page_margin.py +++ b/src/calibre/ebooks/oeb/transforms/page_margin.py @@ -89,7 +89,7 @@ class RemoveFakeMargins: pass else: if ((hasattr(ti, 'startswith') and ti.startswith('-')) or - isinstance(ti, numbers.Number) and ti < 0): + (isinstance(ti, numbers.Number) and ti < 0)): raise NegativeTextIndent() return style.marginLeft, style.marginRight, style return '', '', None diff --git a/src/calibre/gui2/book_details.py b/src/calibre/gui2/book_details.py index 0ea421b5b9..e3d922e12e 100644 --- a/src/calibre/gui2/book_details.py +++ b/src/calibre/gui2/book_details.py @@ -649,7 +649,7 @@ def create_copy_links(menu, data=None): field = data.get('field') if data['type'] == 'author': field = 'authors' - if field and field in ('tags', 'series', 'publisher', 'authors') or is_category(field): + if (field and field in ('tags', 'series', 'publisher', 'authors')) or is_category(field): name = data['name' if data['type'] == 'author' else 'value'] eq = f'{field}:"={name}"'.encode().hex() link_action(_('Link to show books matching {} in calibre').format(name), diff --git a/src/calibre/gui2/central.py b/src/calibre/gui2/central.py index 5bbe0132de..54817cb14a 100644 --- a/src/calibre/gui2/central.py +++ b/src/calibre/gui2/central.py @@ -670,7 +670,7 @@ class CentralContainer(QWidget): hs = h.state if hs is HandleState.both_visible or hs is HandleState.only_side_visible: height = normal_handle_width - if hs is HandleState.only_main_visible and h is self.bottom_handle or (h is self.top_handle and self.separate_cover_browser): + if (hs is HandleState.only_main_visible and h is self.bottom_handle) or (h is self.top_handle and self.separate_cover_browser): height = 0 h.resize(int(central_width), int(height)) available_height -= height diff --git a/src/calibre/gui2/dnd.py b/src/calibre/gui2/dnd.py index 532321e0f1..3b09b494fc 100644 --- a/src/calibre/gui2/dnd.py +++ b/src/calibre/gui2/dnd.py @@ -133,7 +133,7 @@ class DownloadDialog(QDialog): # {{{ def dnd_has_image(md): # Chromium puts image data into application/octet-stream - return md.hasImage() or md.hasFormat('application/octet-stream') and what(None, bytes(md.data('application/octet-stream'))) in image_extensions() + return md.hasImage() or (md.hasFormat('application/octet-stream') and what(None, bytes(md.data('application/octet-stream'))) in image_extensions()) def data_as_string(f, md): diff --git a/src/calibre/gui2/tag_browser/model.py b/src/calibre/gui2/tag_browser/model.py index acd478a029..46abeb70a9 100644 --- a/src/calibre/gui2/tag_browser/model.py +++ b/src/calibre/gui2/tag_browser/model.py @@ -1234,9 +1234,9 @@ class TagsModel(QAbstractItemModel): # {{{ if fm_dest['kind'] == 'user': fm_src = self.db.metadata_for_field(md.column_name) if md.column_name in ['authors', 'publisher', 'series'] or \ - (fm_src['is_custom'] and ( + ((fm_src['is_custom'] and ( fm_src['datatype'] in ['series', 'text', 'enumeration'] and - not fm_src['is_multiple'])or + not fm_src['is_multiple']))or (fm_src['datatype'] == 'composite' and fm_src['display'].get('make_category', False))): mime = 'application/calibre+from_library' diff --git a/src/calibre/library/restore.py b/src/calibre/library/restore.py index f1e953721a..6ec7855a1d 100644 --- a/src/calibre/library/restore.py +++ b/src/calibre/library/restore.py @@ -203,7 +203,7 @@ class Restore(Thread): alm = mi.get('author_link_map', {}) for author, link in iteritems(alm): existing_link, timestamp = self.authors_links.get(author, (None, None)) - if existing_link is None or existing_link != link and timestamp < mi.timestamp: + if existing_link is None or (existing_link != link and timestamp < mi.timestamp): self.authors_links[author] = (link, mi.timestamp) def create_cc_metadata(self): diff --git a/src/calibre/utils/magick/legacy.py b/src/calibre/utils/magick/legacy.py index fc3c66c96b..132cd99d87 100644 --- a/src/calibre/utils/magick/legacy.py +++ b/src/calibre/utils/magick/legacy.py @@ -135,7 +135,7 @@ class Image: return width, height, fmt def remove_border(self, fuzz=None): - if fuzz is not None and fuzz < 0 or fuzz > 255: + if (fuzz is not None and fuzz < 0) or fuzz > 255: fuzz = None self.img = remove_borders_from_image(self.img, fuzz) trim = remove_border diff --git a/src/calibre/utils/mem.py b/src/calibre/utils/mem.py index 6b862a0d81..f04e0859a2 100644 --- a/src/calibre/utils/mem.py +++ b/src/calibre/utils/mem.py @@ -48,4 +48,4 @@ def diff_hists(h1, h2): h2[k] = 0 if h1[k] != h2[k]: print('%s: %d -> %d (%s%d)' % ( - k, h1[k], h2[k], h2[k] > h1[k] and '+' or '', h2[k] - h1[k])) + k, h1[k], h2[k], (h2[k] > h1[k] and '+') or '', h2[k] - h1[k]))