jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1341979?usp=email )
Change subject: Use lazy logging and f-strings for site and API diagnostics
......................................................................
Use lazy logging and f-strings for site and API diagnostics
Pass seven fixed log messages and their arguments separately to defer
interpolation. Use f-strings for three URL and edit-parameter exceptions.
Preserve message text, argument preparation, and validation behavior.
Keep the legacy logevents total-argument handling unchanged; the updated
range message is part of the supported date-range path.
Change-Id: I6a077377d444a6c24cce0247873ba59d76892a13
---
M pywikibot/__init__.py
M pywikibot/data/api/_requests.py
M pywikibot/family.py
M pywikibot/pagegenerators/_factory.py
M pywikibot/site/_apisite.py
M pywikibot/site/_siteinfo.py
6 files changed, 22 insertions(+), 20 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index f2e1a52..64ef994 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -130,8 +130,8 @@
matched_sites.append((family.code, family))
if len(matched_sites) > 1:
- warning('Found multiple matches for URL "{}": {} (use first)'
- .format(url, ', '.join(str(s) for s in matched_sites)))
+ warning('Found multiple matches for URL "%s": %s (use first)',
+ url, ', '.join(str(s) for s in matched_sites))
return matched_sites[0]
diff --git a/pywikibot/data/api/_requests.py b/pywikibot/data/api/_requests.py
index 38d67da..168be82 100644
--- a/pywikibot/data/api/_requests.py
+++ b/pywikibot/data/api/_requests.py
@@ -1005,8 +1005,8 @@
'readonly', # T154011
]
- pywikibot.error('Detected MediaWiki API exception {}{}'
- .format(e, '; retrying' if retry else '; raising'))
+ pywikibot.error('Detected MediaWiki API exception %s%s',
+ e, '; retrying' if retry else '; raising')
param_repr = str(self._params)
pywikibot.log(f'MediaWiki exception {class_name} details:\n'
f' query=\n{pprint.pformat(param_repr)}\n'
diff --git a/pywikibot/family.py b/pywikibot/family.py
index 7624eb0..dc36b36 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -671,8 +671,8 @@
return None
raise RuntimeError(
- 'Found multiple matches for URL "{}": {}'
- .format(url, ', '.join(str(s) for s in matched_sites)))
+ f'Found multiple matches for URL "{url}": '
+ f'{", ".join(str(s) for s in matched_sites)}')
def dbName(self, code) -> str:
"""Return the name of the MySQL database."""
diff --git a/pywikibot/pagegenerators/_factory.py
b/pywikibot/pagegenerators/_factory.py
index 8ee34e8..067f2f9 100644
--- a/pywikibot/pagegenerators/_factory.py
+++ b/pywikibot/pagegenerators/_factory.py
@@ -467,8 +467,8 @@
if start_ or end_:
pywikibot.info(
- 'Fetching log events in range: {} - {}.'
- .format(end or 'beginning of time', start or 'now'))
+ 'Fetching log events in range: %s - %s.',
+ end or 'beginning of time', start or 'now')
# 'user or None', because user might be an empty string when
# 'foo,,bar' was used.
diff --git a/pywikibot/site/_apisite.py b/pywikibot/site/_apisite.py
index c14ec44..7c0c0c3 100644
--- a/pywikibot/site/_apisite.py
+++ b/pywikibot/site/_apisite.py
@@ -1239,8 +1239,8 @@
try:
namespace = _namespaces[ns]
except KeyError:
- pywikibot.warning('Broken namespace alias "{}" (id: {}) on {}'
- .format(item['alias'], ns, self))
+ pywikibot.warning('Broken namespace alias "%s" (id: %s) on %s',
+ item['alias'], ns, self)
else:
if item['alias'] not in namespace:
namespace.aliases.append(item['alias'])
@@ -2094,11 +2094,13 @@
if text_overrides:
if 'text' in kwargs:
- raise ValueError('text cannot be used with any of {}'
- .format(', '.join(text_overrides)))
+ raise ValueError(
+ 'text cannot be used with any of '
+ f'{", ".join(text_overrides)}')
if len(text_overrides) > 1:
- raise ValueError('Multiple text overrides used: {}'
- .format(', '.join(text_overrides)))
+ raise ValueError(
+ 'Multiple text overrides used: '
+ f'{", ".join(text_overrides)}')
text = None
basetimestamp = False
elif 'text' in kwargs:
diff --git a/pywikibot/site/_siteinfo.py b/pywikibot/site/_siteinfo.py
index 3ca94cd..1d085bd 100644
--- a/pywikibot/site/_siteinfo.py
+++ b/pywikibot/site/_siteinfo.py
@@ -168,8 +168,8 @@
return {props[0]: (EMPTY_DEFAULT, False)}
pywikibot.log('Unable to get siteinfo, because at least '
- "one property is unknown: '{}'"
- .format("', '".join(props)))
+ "one property is unknown: '%s'",
+ "', '".join(props))
results = {}
for p in props:
results.update(self._get_siteinfo(p, expiry))
@@ -180,8 +180,8 @@
if invalid_properties:
for invalid_prop in invalid_properties:
result[invalid_prop] = (EMPTY_DEFAULT, False)
- pywikibot.log("Unable to get siprop(s) '{}'"
- .format("', '".join(invalid_properties)))
+ pywikibot.log("Unable to get siprop(s) '%s'",
+ "', '".join(invalid_properties))
# Process valid properties
if 'query' in data:
@@ -241,8 +241,8 @@
props = [prop for prop in props if prop not in self._cache]
if props:
pywikibot.debug(
- "Load siteinfo properties '{}' along with 'general'"
- .format("', '".join(props)))
+ "Load siteinfo properties '%s' along with 'general'",
+ "', '".join(props))
props.append('general')
default_info = self._get_siteinfo(props, expiry)
for prop in props:
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1341979?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: I6a077377d444a6c24cce0247873ba59d76892a13
Gerrit-Change-Number: 1341979
Gerrit-PatchSet: 2
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]