repeated equality comparison (extra-edit)

This commit is contained in:
un-pogaz 2025-10-10 08:24:40 +02:00
parent 0dc4e67529
commit 2c3edf5ad7
9 changed files with 42 additions and 14 deletions

View File

@ -441,7 +441,7 @@ class Build(Command):
os.makedirs(x, exist_ok=True)
pyqt_extensions, extensions = [], []
for ext in all_extensions:
if opts.only not in ('all', ext.name):
if opts.only not in {'all', ext.name}:
continue
if not is_ext_allowed(self.compiling_for, ext):
continue

View File

@ -709,7 +709,7 @@ class KOBO(USBMS):
# for calibre's reference
path = self._main_prefix + path + '.kobo'
# print('Path: ' + path)
elif (ContentType in {'6', '10'}) and (
elif ContentType in {'6', '10'} and (
MimeType == 'application/x-kobo-epub+zip' or (
MimeType == 'application/epub+zip' and self.isTolinoDevice())
):
@ -1797,7 +1797,7 @@ class KOBOTOUCH(KOBO):
allow_shelves = False
if show_debug:
debug_print('KoboTouch:update_booklist - have a deleted book')
elif self.supports_kobo_archive() and (accessibility in {1, 2}):
elif self.supports_kobo_archive() and accessibility in {1, 2}:
playlist_map[lpath].append('Archived')
allow_shelves = True
@ -2192,7 +2192,7 @@ class KOBOTOUCH(KOBO):
if oncard == 'cardb':
print('path from_contentid cardb')
elif (ContentType in {'6', '10'}):
elif ContentType in {'6', '10'}:
if (MimeType == 'application/octet-stream'): # Audiobooks purchased from Kobo are in a different location.
path = self._main_prefix + KOBO_ROOT_DIR_NAME + '/audiobook/' + path
elif (MimeType == 'audio/mpeg' and self.isTolinoDevice()):

View File

@ -2,7 +2,7 @@ def _optimize(tagList, tagName, conversion):
# copy the tag of interest plus any text
newTagList = []
for tag in tagList:
if tag.name in (tagName, 'rawtext'):
if tag.name in {tagName, 'rawtext'}:
newTagList.append(tag)
# now, eliminate any duplicates (leaving the last one)

View File

@ -862,7 +862,7 @@ class MobiReader:
l = self.mobi_html.find(b'<', end)
r = self.mobi_html.find(b'>', end)
anchor = b'<a id="filepos%d"></a>'
if r > -1 and (r < l or l in (end, -1)):
if r > -1 and (r < l or l in {end, -1}):
p = self.mobi_html.rfind(b'<', 0, end + 1)
if (pos < end and p > -1 and not end_tag_re.match(self.mobi_html[p:r]) and
not self.mobi_html[p:r + 1].endswith(b'/>')):

View File

@ -278,7 +278,7 @@ class Text(Element):
if m_self and m_other:
self.raw = m_self.group(1)
other.raw = m_other.group(1)
elif self.font_size_em not in (other.font_size_em, 1.0):
elif self.font_size_em not in {other.font_size_em, 1.0}:
if not self.raw.startswith(r'<span'):
self.raw = f'<span style="font-size:{self.font_size_em!s}em">{self.raw}</span>'
# Try to allow for a very large initial character
@ -948,7 +948,12 @@ class Page:
t.tag = 'h2' # It won't get set later
# Centered if left and right margins are within FACTOR%
# Because indents can waver a bit, use between indent_min and indent_max as == indent
if (lmargin < indent_min or lmargin > indent_max) and lmargin > left_max and lmargin not in (xmargin, ymargin) and lmargin >= rmargin - rmargin * CENTER_FACTOR and lmargin <= rmargin + rmargin * CENTER_FACTOR and '"float:right"' not in t.raw:
if (lmargin < indent_min or lmargin > indent_max) \
and lmargin > left_max \
and lmargin not in {xmargin, ymargin} \
and lmargin >= rmargin - rmargin*CENTER_FACTOR \
and lmargin <= rmargin + rmargin*CENTER_FACTOR \
and '"float:right"' not in t.raw:
# and t.left + t.width + t.left >= self.width + l_offset - t.average_character_width \
# and t.left + t.width + t.left <= self.width + l_offset + t.average_character_width:
t.align = 'C'

View File

@ -426,7 +426,7 @@ class PDFStream:
if fmt == QImage.Format.Format_MonoLSB:
image = image.convertToFormat(QImage.Format.Format_Mono)
fmt = QImage.Format.Format_Mono
elif (fmt not in (QImage.Format.Format_RGB32, QImage.Format.Format_ARGB32)):
elif fmt not in (QImage.Format.Format_RGB32, QImage.Format.Format_ARGB32):
image = image.convertToFormat(QImage.Format.Format_ARGB32)
fmt = QImage.Format.Format_ARGB32

View File

@ -400,7 +400,15 @@ class Inline:
for line in read_obj:
token = line[0:-1]
self.__token_info = ''
if token in {'tx<mc<__________<rdblquote', 'tx<mc<__________<ldblquote', 'tx<mc<__________<lquote', 'tx<mc<__________<rquote', 'tx<mc<__________<emdash', 'tx<mc<__________<endash', 'tx<mc<__________<bullet'}:
if token in {
'tx<mc<__________<rdblquote',
'tx<mc<__________<ldblquote',
'tx<mc<__________<lquote',
'tx<mc<__________<rquote',
'tx<mc<__________<emdash',
'tx<mc<__________<endash',
'tx<mc<__________<bullet',
}:
self.__token_info = 'text'
else:
self.__token_info = line[:16]

View File

@ -122,7 +122,12 @@ class Table:
a row and start a cell.
'''
# 'cell' : ('tb', 'cell______', self.default_func),
if self.__token_info in {'mi<mk<not-in-tbl', 'mi<mk<sect-start', 'mi<mk<sect-close', 'mi<mk<body-close'}:
if self.__token_info in {
'mi<mk<not-in-tbl',
'mi<mk<sect-start',
'mi<mk<sect-close',
'mi<mk<body-close',
}:
self.__close_table(line)
elif self.__token_info == 'mi<mk<pard-start':
self.__start_row_func(line)
@ -423,7 +428,12 @@ class Table:
'''
# cw<tb<cell______<nu<true
# mi<mk<sect-start
if self.__token_info in {'mi<mk<not-in-tbl', 'mi<mk<sect-start', 'mi<mk<sect-close', 'mi<mk<body-close'}:
if self.__token_info in {
'mi<mk<not-in-tbl',
'mi<mk<sect-start',
'mi<mk<sect-close',
'mi<mk<body-close',
}:
self.__end_cell_func(line)
self.__end_row_func(line)
self.__close_table(line)
@ -450,7 +460,12 @@ class Table:
self.__write_obj.write('mi<mk<closecell_\n')
def __in_row_func(self, line):
if self.__token_info in {'mi<mk<not-in-tbl', 'mi<mk<sect-start', 'mi<mk<sect-close', 'mi<mk<body-close'}:
if self.__token_info in {
'mi<mk<not-in-tbl',
'mi<mk<sect-start',
'mi<mk<sect-close',
'mi<mk<body-close',
}:
self.__end_row_func(line)
self.__close_table(line)
self.__write_obj.write(line)

View File

@ -147,7 +147,7 @@ def jpeg_dimensions(stream):
while marker == 0xff:
marker = read_byte()
q = marker
if 192 <= q <= 207 and q not in {196, 204}:
if 0xc0 <= q <= 0xcf and q not in {0xc4, 0xcc}:
# SOFn marker
stream.seek(3, os.SEEK_CUR)
return unpack(b'>HH', read(4))