Skip to content

Commit

Permalink
IMPR: Do not redefine local variable within loop
Browse files Browse the repository at this point in the history
Change-Id: I48a017a86556a0f115c033c69e03b149789e4486
  • Loading branch information
xqt committed Nov 24, 2024
1 parent 426eec4 commit 24539b7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions pywikibot/site/_siteinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ def warn_handler(mod, message) -> bool:
"one property is unknown: '{}'"
.format("', '".join(props)))
results = {}
for prop in props:
results.update(self._get_siteinfo(prop, expiry))
for p in props:
results.update(self._get_siteinfo(p, expiry))
return results
raise

result = {}
if invalid_properties:
for prop in invalid_properties:
result[prop] = (EMPTY_DEFAULT, False)
for invalid_prop in invalid_properties:
result[invalid_prop] = (EMPTY_DEFAULT, False)
pywikibot.log("Unable to get siprop(s) '{}'"
.format("', '".join(invalid_properties)))

Expand Down
12 changes: 6 additions & 6 deletions pywikibot/userinterfaces/terminal_interface_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ def _print(self, text, target_stream) -> None:
# match.split() includes every regex group; for each matched color
# fg_col:b_col, fg_col and bg_col are added to the resulting list.
len_text_parts = len(text_parts[::4])
for index, (text, next_color) in enumerate(zip(text_parts[::4],
text_parts[1::4])):
for index, (txt, next_color) in enumerate(zip(text_parts[::4],
text_parts[1::4])):
current_color = color_stack[-1]
if next_color == 'previous':
if len(color_stack) > 1: # keep the last element in the stack
Expand All @@ -226,15 +226,15 @@ def _print(self, text, target_stream) -> None:
if current_color != next_color:
colored_line = True
if colored_line and not colorized:
if '\n' in text: # Normal end of line
text = text.replace('\n', ' ***\n', 1)
if '\n' in txt: # Normal end of line
txt = txt.replace('\n', ' ***\n', 1)
colored_line = False
elif index == len_text_parts - 1: # Or end of text
text += ' ***'
txt += ' ***'
colored_line = False

# print the text up to the tag.
self._write(text, target_stream)
self._write(txt, target_stream)

if current_color != next_color and colorized:
# set the new color, but only if they change
Expand Down
6 changes: 3 additions & 3 deletions scripts/coordinate_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ def treat_page_and_item(self, page, item) -> None:
return
if page is None:
# running over items, search in linked pages
for page in item.iterlinks():
if page.site.has_extension('GeoData') \
and self.try_import_coordinates_from_page(page, item):
for p in item.iterlinks():
if p.site.has_extension('GeoData') \
and self.try_import_coordinates_from_page(p, item):
break
return

Expand Down
6 changes: 3 additions & 3 deletions scripts/protect.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ def check_protection_level(operation, level, levels, default=None) -> str:
first_char = []
default_char = None
num = 1
for level in levels:
for c in level:
for lev in levels:
for c in lev:
if c not in first_char:
first_char.append(c)
break
else:
first_char.append(str(num))
num += 1
if level == default:
if lev == default:
default_char = first_char[-1]

choice = pywikibot.input_choice(
Expand Down
4 changes: 2 additions & 2 deletions scripts/weblinkchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,10 @@ def log(self, url, error, containing_page, archive_url) -> None:
error_report = f'* {url} ([{archive_url} archive])\n'
else:
error_report = f'* {url}\n'
for (page_title, date, error) in self.history_dict[url]:
for (page_title, date, err) in self.history_dict[url]:
# ISO 8601 formulation
iso_date = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(date))
error_report += f'** In [[{page_title}]] on {iso_date}, {error}\n'
error_report += f'** In [[{page_title}]] on {iso_date}, {err}\n'
pywikibot.info('** Logging link for deletion.')
txtfilename = pywikibot.config.datafilepath(
'deadlinks',
Expand Down

0 comments on commit 24539b7

Please sign in to comment.