Skip to content

Commit 4f520a1

Browse files
committed
IMPR: use f-string instead of old format type
Change-Id: I1d367e53b50fb1daf5914d8d2bae6034af8623ad
1 parent 4e75ba0 commit 4f520a1

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

pywikibot/data/api/_generators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,8 @@ def generator(self):
634634
previous_result_had_data = True
635635
else:
636636
if 'query' not in self.data:
637-
pywikibot.log("%s: 'query' not found in api response." %
638-
self.__class__.__name__)
637+
pywikibot.log(f"{type(self).__name__}: 'query' not found"
638+
' in api response.')
639639
pywikibot.log(str(self.data))
640640

641641
# if (query-)continue is present, self.resultkey might not have

pywikibot/logentries.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ def __missing__(self, key: str) -> None:
6161
for hidden_key, hidden_types in hidden.items():
6262
if hidden_key in self and key in hidden_types:
6363
raise HiddenKeyError(
64-
"Log entry ({}) has a hidden '{}' key and you don't have "
65-
"permission to view it due to '{}'"
66-
.format(self['type'], key, hidden_key))
64+
f'Log entry ({self["type"]}) has a hidden {key!r} key and'
65+
" you don't have permission to view it due to "
66+
f'{hidden_key!r}'
67+
)
6768

6869
raise KeyError(f"Log entry ({self['type']}) has no {key!r} key")
6970

pywikibot/site/_generators.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def preloadpages(
197197
for pagedata in rvgen:
198198
pywikibot.debug(f'Preloading {pagedata}')
199199
try:
200-
if pagedata['title'] not in cache:
200+
if (pd_title := pagedata['title']) not in cache:
201201
# API always returns a "normalized" title which is
202202
# usually the same as the canonical form returned by
203203
# page.title(), but sometimes not (e.g.,
@@ -206,19 +206,18 @@ def preloadpages(
206206
# the response that corresponds to the canonical form
207207
# used in the query.
208208
for key, value in cache.items():
209-
if self.sametitle(key, pagedata['title']):
210-
cache[pagedata['title']] = value
209+
if self.sametitle(key, pd_title):
210+
cache[pd_title] = value
211211
break
212212
else:
213-
pywikibot.warning(
214-
'preloadpages: Query returned unexpected '
215-
"title '{}'".format(pagedata['title']))
213+
pywikibot.warning('preloadpages: Query returned '
214+
f'unexpected title {pd_title!r}')
216215
continue
217216

218217
except KeyError:
219-
pywikibot.debug(f"No 'title' in {pagedata}")
220-
pywikibot.debug(f'{pageids=!s}')
221-
pywikibot.debug(f'titles={list(cache.keys())}')
218+
pywikibot.debug(f"No 'title' in {pagedata}\n"
219+
f'{pageids=!s}\n'
220+
f'titles={list(cache.keys())}')
222221
continue
223222

224223
priority, page = cache[pagedata['title']]

0 commit comments

Comments
 (0)