jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1341944?usp=email )

Change subject: Use f-strings and lazy logging for upload and option messages
......................................................................

Use f-strings and lazy logging for upload and option messages

Convert nine literal formatting expressions in upload diagnostics,
invalid-option messages, and aligned option and query-page displays.
Pass the upload format diagnostic as a template and argument to the logger
to defer interpolation. Preserve message text, representation formatting,
and column widths. Keep dynamic warning templates unchanged.

Change-Id: I92c61b1a8899593457573fd6afb6096de3fcbdf4
---
M pywikibot/bot_choice.py
M pywikibot/data/api/_optionset.py
M pywikibot/pagegenerators/_factory.py
M pywikibot/site/_upload.py
M pywikibot/specialbots/_upload.py
5 files changed, 23 insertions(+), 21 deletions(-)

Approvals:
  jenkins-bot: Verified
  Xqt: Looks good to me, approved




diff --git a/pywikibot/bot_choice.py b/pywikibot/bot_choice.py
index 988341e..4951f27 100644
--- a/pywikibot/bot_choice.py
+++ b/pywikibot/bot_choice.py
@@ -538,7 +538,7 @@
             text = self.pre + '\n'
         width = len(str(self.maximum))
         for i, item in enumerate(self._list, self.minimum):
-            text += '{:>{width}} - {}\n'.format(i, item, width=width)
+            text += f'{i:>{width}} - {item}\n'
         if self.post is not None:
             text += self.post + '\n'
         return text
diff --git a/pywikibot/data/api/_optionset.py b/pywikibot/data/api/_optionset.py
index 25f7300..e1f7f2c 100644
--- a/pywikibot/data/api/_optionset.py
+++ b/pywikibot/data/api/_optionset.py
@@ -97,8 +97,9 @@
             invalid_names = ((self._enabled - self._valid_enable)
                              | (self._disabled - self._valid_disable))
             if invalid_names:
-                raise KeyError('OptionSet already contains invalid name(s) '
-                               '"{}"'.format('", "'.join(invalid_names)))
+                names = '", "'.join(invalid_names)
+                raise KeyError(
+                    f'OptionSet already contains invalid name(s) "{names}"')
         self._site_set = True

     def from_dict(self, dictionary: dict[str, bool | None]) -> None:
@@ -130,8 +131,8 @@
             | (removed - self._valid_enable - self._valid_disable)
         )
         if invalid_names and self._site_set:
-            raise ValueError('Dict contains invalid name(s) "{}"'.format(
-                '", "'.join(invalid_names)))
+            names = '", "'.join(invalid_names)
+            raise ValueError(f'Dict contains invalid name(s) "{names}"')
         self._enabled = enabled | (self._enabled - disabled - removed)
         self._disabled = disabled | (self._disabled - enabled - removed)

diff --git a/pywikibot/pagegenerators/_factory.py 
b/pywikibot/pagegenerators/_factory.py
index 067f2f9..740c6b1 100644
--- a/pywikibot/pagegenerators/_factory.py
+++ b/pywikibot/pagegenerators/_factory.py
@@ -538,7 +538,7 @@
             max_w = max(len(p) for p in pages[::2]) + 4
             txt = 'Available special pages:\n'
             for a, b in zip_longest(pages[::2], pages[1::2], fillvalue=''):
-                txt += '    {a:<{max_w}}{b}\n'.format(a=a, b=b, max_w=max_w)
+                txt += f'    {a:<{max_w}}{b}\n'
             txt += ('\nMaximum number of pages to return is {max} '
                     '({highmax} for bots).\n'.format_map(limit))
             pywikibot.info(txt)
diff --git a/pywikibot/site/_upload.py b/pywikibot/site/_upload.py
index dfc89f0..8e15d21 100644
--- a/pywikibot/site/_upload.py
+++ b/pywikibot/site/_upload.py
@@ -224,14 +224,14 @@
             elif offset is False:
                 if file_size != stash_info['size']:
                     raise ValueError(
-                        'For the file key "{}" the server reported a size '
-                        '{} while the file size is {}'
-                        .format(file_key, stash_info['size'], file_size))
+                        f'For the file key "{file_key}" the server reported '
+                        f'a size {stash_info["size"]} while the file size is '
+                        f'{file_size}')
             elif offset is not False and offset != stash_info['size']:
                 raise ValueError(
-                    'For the file key "{}" the server reported a size {} '
-                    'while the offset was {}'
-                    .format(file_key, stash_info['size'], offset))
+                    f'For the file key "{file_key}" the server reported '
+                    f'a size {stash_info["size"]} while the offset was '
+                    f'{offset}')

             if verify_stash:
                 # The SHA1 was also requested so calculate and compare it
@@ -240,9 +240,9 @@
                 sha1 = compute_file_hash(self.filename, bytes_to_read=offset)
                 if sha1 != stash_info['sha1']:
                     raise ValueError(
-                        'The SHA1 of {} bytes of the stashed "{}" is {} '
-                        'while the local file is {}'
-                        .format(offset, file_key, stash_info['sha1'], sha1))
+                        f'The SHA1 of {offset} bytes of the stashed '
+                        f'"{file_key}" is {stash_info["sha1"]} '
+                        f'while the local file is {sha1}')

         assert offset is not True
         if file_key and file_size is None:
@@ -494,8 +494,8 @@
                     return False

                 if len(warnings) > 1:
-                    warn('The upload returned {} warnings: {}'
-                         .format(len(warnings), ', '.join(warnings)),
+                    warn(f'The upload returned {len(warnings)} warnings: '
+                         f'{", ".join(warnings)}',
                          UserWarning, 3)
                 warning, message = next(iter(warnings.items()))
                 warning = warning_keys.get(warning, warning)
diff --git a/pywikibot/specialbots/_upload.py b/pywikibot/specialbots/_upload.py
index 39320a5..7dc3735 100644
--- a/pywikibot/specialbots/_upload.py
+++ b/pywikibot/specialbots/_upload.py
@@ -324,12 +324,13 @@

             if allowed_formats and ext not in allowed_formats:
                 if self.opt.always:
-                    pywikibot.info('File format is not one of [{}]'
-                                   .format(' '.join(allowed_formats)))
+                    pywikibot.info(
+                        'File format is not one of [%s]',
+                        ' '.join(allowed_formats))

                 elif pywikibot.input_yn(
-                        'File format is not one of [{}], but {!r}. Skip?'
-                        .format(' '.join(allowed_formats), ext)):
+                        'File format is not one of '
+                        f'[{" ".join(allowed_formats)}], but {ext!r}. Skip?'):
                     return None

                 continue

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1341944?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I92c61b1a8899593457573fd6afb6096de3fcbdf4
Gerrit-Change-Number: 1341944
Gerrit-PatchSet: 3
Gerrit-Owner: Mahveotm <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to