From d8aecf09ea81eebcef2af3d9e843f9101cfca21c 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] unsorted dunder all/slots (auto-fix) ruff 'RUF022,RUF023' --- ruff-strict-pep8.toml | 3 +- src/calibre/customize/zipplugin.py | 9 +++- src/calibre/db/categories.py | 20 +++++-- src/calibre/db/fields.py | 4 +- src/calibre/ebooks/metadata/sources/base.py | 2 +- src/calibre/ebooks/oeb/polish/spell.py | 4 +- src/calibre/ebooks/pdf/html_writer.py | 2 +- src/calibre/gui2/tweak_book/editor/canvas.py | 2 +- .../gui2/tweak_book/editor/syntax/css.py | 2 +- src/calibre/gui2/tweak_book/live_css.py | 4 +- src/calibre/gui2/tweak_book/preview.py | 2 +- src/calibre/gui2/viewer/search.py | 15 ++++-- src/calibre/gui2/viewer/toolbars.py | 2 +- src/calibre/spell/dictionary.py | 2 +- src/calibre/srv/http_request.py | 2 +- src/calibre/srv/loop.py | 2 +- src/calibre/srv/metadata.py | 2 +- src/calibre/utils/matcher.py | 7 ++- src/calibre/utils/smtplib.py | 18 +++++-- src/calibre/utils/threadpool.py | 12 ++--- src/calibre/utils/zipfile.py | 53 +++++++++++-------- 21 files changed, 111 insertions(+), 58 deletions(-) diff --git a/ruff-strict-pep8.toml b/ruff-strict-pep8.toml index 46dca61508..90527ef705 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', 'RUF019', 'RUF021', 'RUF022', 'RUF023', 'RUF031', 'RUF034', 'RUF100', + 'RUF001', 'RUF002', 'RUF003', 'RUF005', 'RUF010', 'RUF012', 'RUF013', 'RUF015', 'RUF019', 'RUF021', 'RUF031', 'RUF034', 'RUF100', ] select = [ 'E', 'F', 'I', 'W', 'INT', @@ -31,6 +31,7 @@ select = [ [lint.per-file-ignores] "recipes/*" = ['UP'] "manual/plugin_examples/*" = ['UP'] +"setup/commands.py" = ['RUF022'] "src/calibre/*" = ['UP031'] "src/calibre/ebooks/unihandecode/*codepoints.py" = ['E501'] "src/calibre/ebooks/metadata/sources/*" = ['UP'] diff --git a/src/calibre/customize/zipplugin.py b/src/calibre/customize/zipplugin.py index 34592057a2..749fd34acb 100644 --- a/src/calibre/customize/zipplugin.py +++ b/src/calibre/customize/zipplugin.py @@ -138,8 +138,13 @@ def load_translations(namespace, zfp): class CalibrePluginLoader: __slots__ = ( - 'plugin_name', 'fullname_in_plugin', 'zip_file_path', '_is_package', 'names', - 'filename', 'all_names' + '_is_package', + 'all_names', + 'filename', + 'fullname_in_plugin', + 'names', + 'plugin_name', + 'zip_file_path' ) def __init__(self, plugin_name, fullname_in_plugin, zip_file_path, names, filename, is_package, all_names): diff --git a/src/calibre/db/categories.py b/src/calibre/db/categories.py index 19ebb2994f..1480805e94 100644 --- a/src/calibre/db/categories.py +++ b/src/calibre/db/categories.py @@ -21,9 +21,23 @@ CATEGORY_SORTS = ('name', 'popularity', 'rating') # This has to be a tuple not class Tag: - __slots__ = ('name', 'original_name', 'id', 'count', 'state', 'is_hierarchical', - 'is_editable', 'is_searchable', 'id_set', 'avg_rating', 'sort', - 'use_sort_as_name', 'category', 'search_expression', 'original_categories') + __slots__ = ( + 'avg_rating', + 'category', + 'count', + 'id', + 'id_set', + 'is_editable', + 'is_hierarchical', + 'is_searchable', + 'name', + 'original_categories', + 'original_name', + 'search_expression', + 'sort', + 'state', + 'use_sort_as_name', + ) def __init__(self, name, id=None, count=0, state=0, avg=0, sort=None, category=None, id_set=None, search_expression=None, diff --git a/src/calibre/db/fields.py b/src/calibre/db/fields.py index a3d1027588..885a722097 100644 --- a/src/calibre/db/fields.py +++ b/src/calibre/db/fields.py @@ -471,7 +471,7 @@ class OnDeviceField(OneToOneField): class LazySortMap: - __slots__ = ('default_sort_key', 'sort_key_func', 'id_map', 'cache') + __slots__ = ('cache', 'default_sort_key', 'id_map', 'sort_key_func') def __init__(self, default_sort_key, sort_key_func, id_map): self.default_sort_key = default_sort_key @@ -701,7 +701,7 @@ class FormatsField(ManyToManyField): class LazySeriesSortMap: - __slots__ = ('default_sort_key', 'sort_key_func', 'id_map', 'cache') + __slots__ = ('cache', 'default_sort_key', 'id_map', 'sort_key_func') def __init__(self, default_sort_key, sort_key_func, id_map): self.default_sort_key = default_sort_key diff --git a/src/calibre/ebooks/metadata/sources/base.py b/src/calibre/ebooks/metadata/sources/base.py index eb0218ce0e..ac8644a10a 100644 --- a/src/calibre/ebooks/metadata/sources/base.py +++ b/src/calibre/ebooks/metadata/sources/base.py @@ -164,7 +164,7 @@ def fixcase(x): class Option: - __slots__ = ['type', 'default', 'label', 'desc', 'name', 'choices'] + __slots__ = ['choices', 'default', 'desc', 'label', 'name', 'type'] def __init__(self, name, type_, default, label, desc, choices=None): ''' diff --git a/src/calibre/ebooks/oeb/polish/spell.py b/src/calibre/ebooks/oeb/polish/spell.py index f33f7ccfd9..50ed4b0f4c 100644 --- a/src/calibre/ebooks/oeb/polish/spell.py +++ b/src/calibre/ebooks/oeb/polish/spell.py @@ -22,7 +22,7 @@ _patterns = None class Patterns: - __slots__ = ('sanitize_invisible_pat', 'split_pat', 'digit_pat', 'fr_elision_pat') + __slots__ = ('digit_pat', 'fr_elision_pat', 'sanitize_invisible_pat', 'split_pat') def __init__(self): import regex @@ -56,7 +56,7 @@ class CharCounter: class Location: - __slots__ = ('file_name', 'sourceline', 'original_word', 'location_node', 'node_item', 'elided_prefix') + __slots__ = ('elided_prefix', 'file_name', 'location_node', 'node_item', 'original_word', 'sourceline') def __init__(self, file_name=None, elided_prefix='', original_word=None, location_node=None, node_item=(None, None)): self.file_name, self.elided_prefix, self.original_word = file_name, elided_prefix, original_word diff --git a/src/calibre/ebooks/pdf/html_writer.py b/src/calibre/ebooks/pdf/html_writer.py index 20a1bab3c7..c492b62f35 100644 --- a/src/calibre/ebooks/pdf/html_writer.py +++ b/src/calibre/ebooks/pdf/html_writer.py @@ -624,7 +624,7 @@ def make_anchors_unique(container, log): class AnchorLocation: - __slots__ = ('pagenum', 'left', 'top', 'zoom') + __slots__ = ('left', 'pagenum', 'top', 'zoom') def __init__(self, pagenum=1, left=0, top=0, zoom=0): self.pagenum, self.left, self.top, self.zoom = pagenum, left, top, zoom diff --git a/src/calibre/gui2/tweak_book/editor/canvas.py b/src/calibre/gui2/tweak_book/editor/canvas.py index 97165a7be4..6cd5f92d0a 100644 --- a/src/calibre/gui2/tweak_book/editor/canvas.py +++ b/src/calibre/gui2/tweak_book/editor/canvas.py @@ -58,7 +58,7 @@ def painter(func): class SelectionState: - __slots__ = ('last_press_point', 'current_mode', 'rect', 'in_selection', 'drag_corner', 'dragging', 'last_drag_pos') + __slots__ = ('current_mode', 'drag_corner', 'dragging', 'in_selection', 'last_drag_pos', 'last_press_point', 'rect') def __init__(self): self.reset() diff --git a/src/calibre/gui2/tweak_book/editor/syntax/css.py b/src/calibre/gui2/tweak_book/editor/syntax/css.py index edc04c7828..2ad3b65b43 100644 --- a/src/calibre/gui2/tweak_book/editor/syntax/css.py +++ b/src/calibre/gui2/tweak_book/editor/syntax/css.py @@ -144,7 +144,7 @@ IN_COMMENT_CONTENT = 5 class CSSState: - __slots__ = ('parse', 'blocks') + __slots__ = ('blocks', 'parse') def __init__(self): self.parse = NORMAL diff --git a/src/calibre/gui2/tweak_book/live_css.py b/src/calibre/gui2/tweak_book/live_css.py index 9b102444ca..efae140bc5 100644 --- a/src/calibre/gui2/tweak_book/live_css.py +++ b/src/calibre/gui2/tweak_book/live_css.py @@ -109,7 +109,7 @@ class Heading(QWidget): # {{{ class Cell: # {{{ - __slots__ = ('rect', 'text', 'right_align', 'color_role', 'override_color', 'swatch', 'is_overriden') + __slots__ = ('color_role', 'is_overriden', 'override_color', 'rect', 'right_align', 'swatch', 'text') SIDE_MARGIN = 5 FLAGS = Qt.AlignmentFlag.AlignVCenter | Qt.TextFlag.TextSingleLine | Qt.TextFlag.TextIncludeTrailingSpaces @@ -386,7 +386,7 @@ class Box(QWidget): class Property: - __slots__ = 'name', 'value', 'important', 'color', 'specificity', 'is_overriden' + __slots__ = 'color', 'important', 'is_overriden', 'name', 'specificity', 'value' def __init__(self, prop, specificity=()): self.name, self.value, self.important, self.color = prop diff --git a/src/calibre/gui2/tweak_book/preview.py b/src/calibre/gui2/tweak_book/preview.py index 98465cb05f..bdc7ff7f73 100644 --- a/src/calibre/gui2/tweak_book/preview.py +++ b/src/calibre/gui2/tweak_book/preview.py @@ -78,7 +78,7 @@ def parse_html(raw): class ParseItem: - __slots__ = ('name', 'length', 'fingerprint', 'parsing_done', 'parsed_data') + __slots__ = ('fingerprint', 'length', 'name', 'parsed_data', 'parsing_done') def __init__(self, name): self.name = name diff --git a/src/calibre/gui2/viewer/search.py b/src/calibre/gui2/viewer/search.py index 4963726096..c85bd88f01 100644 --- a/src/calibre/gui2/viewer/search.py +++ b/src/calibre/gui2/viewer/search.py @@ -183,9 +183,18 @@ class SearchFinished: class SearchResult: __slots__ = ( - 'search_query', 'before', 'text', 'after', 'q', 'spine_idx', - 'index', 'file_name', 'is_hidden', 'offset', 'toc_nodes', - 'result_num' + 'after', + 'before', + 'file_name', + 'index', + 'is_hidden', + 'offset', + 'q', + 'result_num', + 'search_query', + 'spine_idx', + 'text', + 'toc_nodes' ) def __init__(self, search_query, before, text, after, q, name, spine_idx, index, offset, result_num): diff --git a/src/calibre/gui2/viewer/toolbars.py b/src/calibre/gui2/viewer/toolbars.py index 75b6161fff..9455f1b49c 100644 --- a/src/calibre/gui2/viewer/toolbars.py +++ b/src/calibre/gui2/viewer/toolbars.py @@ -40,7 +40,7 @@ from calibre.utils.localization import _ class Action: - __slots__ = ('icon', 'text', 'shortcut_action') + __slots__ = ('icon', 'shortcut_action', 'text') def __init__(self, icon=None, text=None, shortcut_action=None): self.icon, self.text, self.shortcut_action = QIcon.ic(icon), text, shortcut_action diff --git a/src/calibre/spell/dictionary.py b/src/calibre/spell/dictionary.py index 04923b9f76..a26f57e7f6 100644 --- a/src/calibre/spell/dictionary.py +++ b/src/calibre/spell/dictionary.py @@ -32,7 +32,7 @@ not_present = object() class UserDictionary: - __slots__ = ('name', 'is_active', 'words') + __slots__ = ('is_active', 'name', 'words') def __init__(self, **kwargs): self.name = kwargs['name'] diff --git a/src/calibre/srv/http_request.py b/src/calibre/srv/http_request.py index c07941841e..b0d4c54e9b 100644 --- a/src/calibre/srv/http_request.py +++ b/src/calibre/srv/http_request.py @@ -134,7 +134,7 @@ class HTTPHeaderParser: Headers which are repeated are folded together using a comma if their specification so dictates. ''' - __slots__ = ('hdict', 'lines', 'finished') + __slots__ = ('finished', 'hdict', 'lines') def __init__(self): self.hdict = MultiDict() diff --git a/src/calibre/srv/loop.py b/src/calibre/srv/loop.py index c0ea6539dd..ac5597dfdc 100644 --- a/src/calibre/srv/loop.py +++ b/src/calibre/srv/loop.py @@ -49,7 +49,7 @@ class ReadBuffer: # {{{ ' A ring buffer used to speed up the readline() implementation by minimizing recv() calls ' - __slots__ = ('ba', 'buf', 'read_pos', 'write_pos', 'full_state') + __slots__ = ('ba', 'buf', 'full_state', 'read_pos', 'write_pos') def __init__(self, size=4096): self.ba = bytearray(size) diff --git a/src/calibre/srv/metadata.py b/src/calibre/srv/metadata.py index d6289987d0..14c1a4fb37 100644 --- a/src/calibre/srv/metadata.py +++ b/src/calibre/srv/metadata.py @@ -213,7 +213,7 @@ CategoriesSettings = namedtuple( class GroupedSearchTerms: - __slots__ = ('keys', 'vals', 'hash') + __slots__ = ('hash', 'keys', 'vals') def __init__(self, src): self.keys = frozenset(src) diff --git a/src/calibre/utils/matcher.py b/src/calibre/utils/matcher.py index ee85d4a568..2131855981 100644 --- a/src/calibre/utils/matcher.py +++ b/src/calibre/utils/matcher.py @@ -226,7 +226,12 @@ def process_item(ctx, haystack, needle): class PyScorer: __slots__ = ( - 'level1', 'level2', 'level3', 'max_score_per_char', 'items', 'memory' + 'items', + 'level1', + 'level2', + 'level3', + 'max_score_per_char', + 'memory' ) def __init__( diff --git a/src/calibre/utils/smtplib.py b/src/calibre/utils/smtplib.py index f9c07146ad..d5463f1e73 100644 --- a/src/calibre/utils/smtplib.py +++ b/src/calibre/utils/smtplib.py @@ -54,10 +54,20 @@ from sys import stderr from polyglot.builtins import string_or_bytes -__all__ = ['SMTPException', 'SMTPServerDisconnected', 'SMTPResponseException', - 'SMTPSenderRefused', 'SMTPRecipientsRefused', 'SMTPDataError', - 'SMTPConnectError', 'SMTPHeloError', 'SMTPAuthenticationError', - 'quoteaddr', 'quotedata', 'SMTP'] +__all__ = [ + 'SMTP', + 'SMTPAuthenticationError', + 'SMTPConnectError', + 'SMTPDataError', + 'SMTPException', + 'SMTPHeloError', + 'SMTPRecipientsRefused', + 'SMTPResponseException', + 'SMTPSenderRefused', + 'SMTPServerDisconnected', + 'quoteaddr', + 'quotedata', +] SMTP_PORT = 25 SMTP_SSL_PORT = 465 diff --git a/src/calibre/utils/threadpool.py b/src/calibre/utils/threadpool.py index 4c9d501f34..ce5770c26e 100644 --- a/src/calibre/utils/threadpool.py +++ b/src/calibre/utils/threadpool.py @@ -31,12 +31,12 @@ Website : http://chrisarndt.de/en/software/python/threadpool/ ''' __all__ = [ - 'makeRequests', - 'NoResultsPending', - 'NoWorkersAvailable', - 'ThreadPool', - 'WorkRequest', - 'WorkerThread' + 'NoResultsPending', + 'NoWorkersAvailable', + 'ThreadPool', + 'WorkRequest', + 'WorkerThread', + 'makeRequests' ] __author__ = 'Christopher Arndt' diff --git a/src/calibre/utils/zipfile.py b/src/calibre/utils/zipfile.py index a62980e1c2..13e0ddcff9 100644 --- a/src/calibre/utils/zipfile.py +++ b/src/calibre/utils/zipfile.py @@ -26,8 +26,17 @@ except ImportError: zlib = None crc32 = binascii.crc32 -__all__ = ['BadZipfile', 'error', 'ZIP_STORED', 'ZIP_DEFLATED', 'is_zipfile', - 'ZipInfo', 'ZipFile', 'PyZipFile', 'LargeZipFile'] +__all__ = [ + 'ZIP_DEFLATED', + 'ZIP_STORED', + 'BadZipfile', + 'LargeZipFile', + 'PyZipFile', + 'ZipFile', + 'ZipInfo', + 'error', + 'is_zipfile', +] def decode_zip_internal_file_name(fname, flags): @@ -305,26 +314,26 @@ class ZipInfo : '''Class with attributes describing each file in the ZIP archive.''' __slots__ = ( - 'orig_filename', - 'filename', - 'date_time', - 'compress_type', - 'comment', - 'extra', - 'create_system', - 'create_version', - 'extract_version', - 'reserved', - 'flag_bits', - 'volume', - 'internal_attr', - 'external_attr', - 'header_offset', - 'CRC', - 'compress_size', - 'file_size', - '_raw_time', - 'file_offset', + 'CRC', + '_raw_time', + 'comment', + 'compress_size', + 'compress_type', + 'create_system', + 'create_version', + 'date_time', + 'external_attr', + 'extra', + 'extract_version', + 'file_offset', + 'file_size', + 'filename', + 'flag_bits', + 'header_offset', + 'internal_attr', + 'orig_filename', + 'reserved', + 'volume', ) def __init__(self, filename='NoName', date_time=(1980,1,1,0,0,0)):