jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1341940?usp=email )
Change subject: Use f-strings for configuration and Wikibase diagnostics
......................................................................
Use f-strings for configuration and Wikibase diagnostics
Replace five literal str.format() expressions in configuration,
sitelink, Wikibase namespace and repository, and API action diagnostics.
Keep the existing message text and lookups. Name the allowed-type list
before interpolation to retain compatibility with Python 3.9.
Change-Id: I74ac8574e687a1661dd6543aabf89b4a5d0a0572
---
M pywikibot/config.py
M pywikibot/data/api/_generators.py
M pywikibot/page/_collections.py
M pywikibot/page/_wikibase.py
4 files changed, 15 insertions(+), 15 deletions(-)
Approvals:
Mahveotm: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/config.py b/pywikibot/config.py
index f60988d..647339b 100644
--- a/pywikibot/config.py
+++ b/pywikibot/config.py
@@ -965,11 +965,11 @@
actual_type: type,
allowed_types: tuple[type, ...],
) -> None:
+ allowed_type_names = '", "'.join(t.__name__ for t in allowed_types)
super().__init__(
- 'Configuration variable "{}" is defined as "{}" in '
- 'your {} but expected "{}".'
- .format(name, actual_type.__name__, user_config_file,
- '", "'.join(t.__name__ for t in allowed_types)))
+ f'Configuration variable "{name}" is defined as '
+ f'"{actual_type.__name__}" in your {user_config_file} '
+ f'but expected "{allowed_type_names}".')
def _assert_default_type(
diff --git a/pywikibot/data/api/_generators.py
b/pywikibot/data/api/_generators.py
index fcbf3d0..e6d7aac 100644
--- a/pywikibot/data/api/_generators.py
+++ b/pywikibot/data/api/_generators.py
@@ -299,8 +299,9 @@
kwargs = self._clean_kwargs(kwargs) # hasn't been called yet
parameters = kwargs['parameters']
if 'action' in parameters and parameters['action'] != 'query':
- raise Error("{}: 'action' must be 'query', not {}"
- .format(self.__class__.__name__, kwargs['action']))
+ raise Error(
+ f"{self.__class__.__name__}: 'action' must be 'query', "
+ f"not {kwargs['action']}")
parameters['action'] = 'query'
# make sure request type is valid, and get limit key if any
for modtype in ('generator', 'list', 'prop', 'meta'):
diff --git a/pywikibot/page/_collections.py b/pywikibot/page/_collections.py
index 6735e23..2e6ac13 100644
--- a/pywikibot/page/_collections.py
+++ b/pywikibot/page/_collections.py
@@ -436,8 +436,8 @@
json = {'site': key, 'title': json}
elif key != json['site']:
raise ValueError(
- "Key '{}' doesn't match the site of the value: '{}'"
- .format(key, json['site']))
+ f"Key '{key}' doesn't match the site of the value: "
+ f"'{json['site']}'")
norm_data[key] = json
else:
for obj in data:
diff --git a/pywikibot/page/_wikibase.py b/pywikibot/page/_wikibase.py
index d05a999..2e1a3a4 100644
--- a/pywikibot/page/_wikibase.py
+++ b/pywikibot/page/_wikibase.py
@@ -640,9 +640,9 @@
if self._namespace:
if self._namespace != entity_type_ns:
- raise ValueError('Namespace "{}" is not valid for Wikibase'
- ' entity type "{}"'
- .format(int(kwargs['ns']), entity_type))
+ raise ValueError(
+ f'Namespace "{int(kwargs["ns"])}" is not valid for '
+ f'Wikibase entity type "{entity_type}"')
else:
self._namespace = entity_type_ns
kwargs['ns'] = self._namespace.id
@@ -1116,10 +1116,9 @@
base_uri, _, qid = uri.rpartition('/')
if base_uri != site.concept_base_uri.rstrip('/'):
raise ValueError(
- 'The supplied data repository ({repo}) does not correspond to '
- 'that of the item ({item})'.format(
- repo=site.concept_base_uri.rstrip('/'),
- item=base_uri))
+ 'The supplied data repository '
+ f'({site.concept_base_uri.rstrip("/")}) does not correspond '
+ f'to that of the item ({base_uri})')
item = cls(site, qid)
if not lazy_load and not item.exists():
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1341940?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: I74ac8574e687a1661dd6543aabf89b4a5d0a0572
Gerrit-Change-Number: 1341940
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <[email protected]>
Gerrit-Reviewer: Mahveotm <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]