From dcc86ee4ef21d2a24a61db08911811c9b184b8d7 Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Fri, 24 Jan 2025 11:14:20 +0100 Subject: [PATCH] explicit f-string conversion (extra-edit) --- recipes/alternatives_economiques.recipe | 4 ++-- recipes/arret_sur_images.recipe | 8 ++++---- recipes/le_canard_enchaine.recipe | 2 +- recipes/readitlater.recipe | 8 ++++---- src/calibre/ebooks/lrf/objects.py | 4 ++-- src/calibre/ebooks/rtf2xml/pict.py | 2 +- src/calibre/gui2/dialogs/duplicates.py | 2 +- src/calibre/gui2/dialogs/metadata_bulk.py | 2 +- src/calibre/gui2/dialogs/template_line_editor.py | 2 +- src/calibre/gui2/tweak_book/spell.py | 2 +- src/calibre/library/catalogs/epub_mobi_builder.py | 12 ++++++------ 11 files changed, 24 insertions(+), 24 deletions(-) diff --git a/recipes/alternatives_economiques.recipe b/recipes/alternatives_economiques.recipe index bcb98ccf74..5d5cda5911 100644 --- a/recipes/alternatives_economiques.recipe +++ b/recipes/alternatives_economiques.recipe @@ -92,7 +92,7 @@ class AlternativesEconomiques(BasicNewsRecipe): display_name = section_name.replace('-', ' ').title() articles.append((display_name, feed_articles[:self.max_articles_per_feed])) except Exception as e: - self.log.error(f'Error processing {section_name}: {e!s}') + self.log.error(f'Error processing {section_name}: {e}') continue return articles @@ -133,7 +133,7 @@ class AlternativesEconomiques(BasicNewsRecipe): 'description': '' }) except Exception as e: - self.log.error(f'Error getting H1 title for {article_url}: {e!s}') + self.log.error(f'Error getting H1 title for {article_url}: {e}') continue return feed_articles diff --git a/recipes/arret_sur_images.recipe b/recipes/arret_sur_images.recipe index b40642ecc0..b4c0ba79c4 100644 --- a/recipes/arret_sur_images.recipe +++ b/recipes/arret_sur_images.recipe @@ -125,7 +125,7 @@ class ArretSurImages(BasicNewsRecipe): else: print("Échec de l'authentification - Vérifiez vos identifiants") except Exception as e: - print(f"Erreur lors de l'authentification: {e!s}") + print(f"Erreur lors de l'authentification: {e}") return br def get_article_url(self, article): @@ -162,7 +162,7 @@ class ArretSurImages(BasicNewsRecipe): ''' except Exception as e: - print(f'Erreur preprocessing HTML: {e!s}') + print(f'Erreur preprocessing HTML: {e}') return raw_html def preprocess_html(self, soup): @@ -186,11 +186,11 @@ class ArretSurImages(BasicNewsRecipe): else: tag.replace_with(img_tag) except Exception as e: - print(f'Erreur processing image: {e!s}') + print(f'Erreur processing image: {e}') tag.decompose() else: tag.decompose() return soup except Exception as e: - print(f'Erreur preprocessing HTML: {e!s}') + print(f'Erreur preprocessing HTML: {e}') return soup diff --git a/recipes/le_canard_enchaine.recipe b/recipes/le_canard_enchaine.recipe index 950d0c50d3..ff8779ce54 100644 --- a/recipes/le_canard_enchaine.recipe +++ b/recipes/le_canard_enchaine.recipe @@ -122,7 +122,7 @@ class LeCanardEnchaine(BasicNewsRecipe): print(f' {len(unique_articles)} articles trouvés') except Exception as e: - print(f'Erreur sur {section_title}: {e!s}') + print(f'Erreur sur {section_title}: {e}') return feeds diff --git a/recipes/readitlater.recipe b/recipes/readitlater.recipe index 475611ea77..afd2626e7c 100644 --- a/recipes/readitlater.recipe +++ b/recipes/readitlater.recipe @@ -75,12 +75,12 @@ class Pocket(BasicNewsRecipe): def get_auth_uri(self): '''Quick function to return the authentication part of the url''' uri = '' - uri = u'{0}&apikey={1!s}'.format(uri, self.apikey) + uri = u'{0}&apikey={1}'.format(uri, self.apikey) if self.username is None or self.password is None: self.user_error('Username or password is blank.') else: - uri = u'{0}&username={1!s}'.format(uri, self.username) - uri = u'{0}&password={1!s}'.format(uri, self.password) + uri = u'{0}&username={1}'.format(uri, self.username) + uri = u'{0}&password={1}'.format(uri, self.password) return uri def get_pull_articles_uri(self): @@ -88,7 +88,7 @@ class Pocket(BasicNewsRecipe): uri = u'{0}&state={1}'.format(uri, u'unread') uri = u'{0}&contentType={1}'.format(uri, u'article') uri = u'{0}&sort={1}'.format(uri, self.sort_method) - uri = u'{0}&count={1!s}'.format(uri, self.max_articles_per_feed) + uri = u'{0}&count={1}'.format(uri, self.max_articles_per_feed) if self.only_pull_tag is not None: uri = u'{0}&tag={1}'.format(uri, self.only_pull_tag) return uri diff --git a/src/calibre/ebooks/lrf/objects.py b/src/calibre/ebooks/lrf/objects.py index b19a4696a1..9e8e55108a 100644 --- a/src/calibre/ebooks/lrf/objects.py +++ b/src/calibre/ebooks/lrf/objects.py @@ -86,7 +86,7 @@ class LRFObject: if h[1] != '' and h[0] != '': setattr(self, h[0], val) else: - raise LRFParseError(f'Unknown tag in {self.__class__.__name__}: {tag!s}') + raise LRFParseError(f'Unknown tag in {self.__class__.__name__}: {tag}') def __iter__(self): yield from range(0) @@ -129,7 +129,7 @@ class LRFContentObject(LRFObject): func, args = action[0], (action[1],) getattr(self, func)(tag, *args) else: - raise LRFParseError(f'Unknown tag in {self.__class__.__name__}: {tag!s}') + raise LRFParseError(f'Unknown tag in {self.__class__.__name__}: {tag}') def __iter__(self): yield from self._contents diff --git a/src/calibre/ebooks/rtf2xml/pict.py b/src/calibre/ebooks/rtf2xml/pict.py index 65e0d3458f..0cc750b88c 100644 --- a/src/calibre/ebooks/rtf2xml/pict.py +++ b/src/calibre/ebooks/rtf2xml/pict.py @@ -77,7 +77,7 @@ class Pict: try: os.mkdir(self.__dir_name) except OSError as msg: - msg = f"{msg!s}Couldn't make directory '{self.__dir_name}':\n" + msg = f"{msg}Couldn't make directory '{self.__dir_name}':\n" raise self.__bug_handler else: if self.__run_level > 1: diff --git a/src/calibre/gui2/dialogs/duplicates.py b/src/calibre/gui2/dialogs/duplicates.py index 89defacc9e..40b7899259 100644 --- a/src/calibre/gui2/dialogs/duplicates.py +++ b/src/calibre/gui2/dialogs/duplicates.py @@ -146,7 +146,7 @@ class DuplicatesQuestion(QDialog): for i in range(self.dup_list.topLevelItemCount()): x = self.dup_list.topLevelItem(i) check = '✓' if x.checkState(0) == Qt.CheckState.Checked else '✗' - title = f'{check} {x.text(0)!s}' + title = f'{check} {x.text(0)}' dups = [] for child in (x.child(j) for j in range(x.childCount())): dups.append('\t' + str(child.text(0))) diff --git a/src/calibre/gui2/dialogs/metadata_bulk.py b/src/calibre/gui2/dialogs/metadata_bulk.py index ac6146be7b..6c069f7d25 100644 --- a/src/calibre/gui2/dialogs/metadata_bulk.py +++ b/src/calibre/gui2/dialogs/metadata_bulk.py @@ -965,7 +965,7 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog): break mi.append(self.db.new_api.get_proxy_metadata(_id)) except Exception as e: - prints(f'TemplateLineEditor: exception fetching metadata: {e!s}') + prints(f'TemplateLineEditor: exception fetching metadata: {e}') mi = None t = TemplateDialog(self, self.s_r_template.text(), mi=mi) t.setWindowTitle(_('Edit search/replace template')) diff --git a/src/calibre/gui2/dialogs/template_line_editor.py b/src/calibre/gui2/dialogs/template_line_editor.py index bace207d23..6f500e92f9 100644 --- a/src/calibre/gui2/dialogs/template_line_editor.py +++ b/src/calibre/gui2/dialogs/template_line_editor.py @@ -30,7 +30,7 @@ class TemplateLineEditor(QLineEdit): mi.append(db.new_api.get_metadata(_id)) self.mi = mi except Exception as e: - prints(f'TemplateLineEditor: exception fetching metadata: {e!s}') + prints(f'TemplateLineEditor: exception fetching metadata: {e}') self.mi = None self.setClearButtonEnabled(True) diff --git a/src/calibre/gui2/tweak_book/spell.py b/src/calibre/gui2/tweak_book/spell.py index a6fc8267b4..0933ec6be1 100644 --- a/src/calibre/gui2/tweak_book/spell.py +++ b/src/calibre/gui2/tweak_book/spell.py @@ -682,7 +682,7 @@ class ManageDictionaries(Dialog): # {{{ x.setData(0, Qt.ItemDataRole.FontRole, bf if x is item else None) lc = str(item.parent().data(0, Qt.ItemDataRole.UserRole)) pl = dprefs['preferred_locales'] - pl[lc] = f'{lc}-{item.data(0, Qt.ItemDataRole.UserRole)!s}' + pl[lc] = f'{lc}-{item.data(0, Qt.ItemDataRole.UserRole)}' dprefs['preferred_locales'] = pl def init_dictionary(self, item): diff --git a/src/calibre/library/catalogs/epub_mobi_builder.py b/src/calibre/library/catalogs/epub_mobi_builder.py index cb1b405b2e..dc0cc7e28b 100644 --- a/src/calibre/library/catalogs/epub_mobi_builder.py +++ b/src/calibre/library/catalogs/epub_mobi_builder.py @@ -557,10 +557,10 @@ class CatalogBuilder: if self.opts.fmt == 'mobi': # Exit if building MOBI error_msg = _('

Inconsistent author sort values for author
' + - f"'{author[0]!s}':

" + - f'

{author[1]!s} != {current_author[1]!s}

' + + f"'{author[0]}':

" + + f'

{author[1]} != {current_author[1]}

' + '

Unable to build MOBI catalog.
' + - f"Select all books by '{author[0]!s}', apply correct Author Sort value in Edit Metadata dialog, then rebuild the catalog.\n

") # noqa: E501 + f"Select all books by '{author[0]}', apply correct Author Sort value in Edit Metadata dialog, then rebuild the catalog.\n

") # noqa: E501 self.opts.log.warn('\n*** Metadata error ***') self.opts.log.warn(error_msg) @@ -573,8 +573,8 @@ class CatalogBuilder: if not self.error: self.error.append('Author sort mismatch') - error_msg = _(f"Warning: Inconsistent author sort values for author '{author[0]!s}':\n" + - f' {author[1]!s} != {current_author[1]!s}\n') + error_msg = _(f"Warning: Inconsistent author sort values for author '{author[0]}':\n" + + f' {author[1]} != {current_author[1]}\n') self.opts.log.warn('\n*** Metadata warning ***') self.opts.log.warn(error_msg) self.error.append(error_msg) @@ -793,7 +793,7 @@ class CatalogBuilder: if self.DEBUG and self.opts.verbose: tl = [i['title'] for i in books_by_author] lt = max(tl, key=len) - fs = '{:<6}{:<%d} {:<%d} {!s}' % (len(lt), len(las)) + fs = '{:<6}{:<%d} {:<%d} {}' % (len(lt), len(las)) print(fs.format('', 'Title', 'Author', 'Series')) for i in books_by_author: print(fs.format('', i['title'], i['author_sort'], i['series']))