jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/688347 )
Change subject: [W0120] Useless else clause detected on the loop ......................................................................
[W0120] Useless else clause detected on the loop
When a loop specifies no break statement, the else clause will always execute when the loop sequence is empty, thus making it useless. It is recommended to have the statements under else in the same scope as the loop itself. If the else clause does not always execute at the end of a loop clause, then the code should add a break statement within the loop block.
Change-Id: I57a8b70da399a869554c8ab78e6eefad18ac1f6d --- M docs/conf.py M pywikibot/bot.py M pywikibot/bot_choice.py M pywikibot/comms/eventstreams.py M pywikibot/data/api.py M pywikibot/site/_apisite.py M scripts/interwiki.py M tests/textlib_tests.py 8 files changed, 28 insertions(+), 30 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/docs/conf.py b/docs/conf.py index 4be6958..d3e68ae 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -493,8 +493,8 @@ return safe_getattr(obj, name, *defargs)
return prop - else: - return safe_getattr(obj, name, *defargs) + + return safe_getattr(obj, name, *defargs)
def setup(app): diff --git a/pywikibot/bot.py b/pywikibot/bot.py index 08fbdc3..0d90522 100644 --- a/pywikibot/bot.py +++ b/pywikibot/bot.py @@ -645,8 +645,8 @@ for c in self.choices: if c.shortcut == choice: return c.handle() - else: - raise ValueError('Invalid choice "{}"'.format(choice)) + + raise ValueError('Invalid choice "{}"'.format(choice))
def __call__(self, link, text, groups, rng): """Ask user how the selected link should be replaced.""" @@ -1532,8 +1532,8 @@ # Process the page self.treat(page) self._treat_counter += 1 - else: - self._generator_completed = True + + self._generator_completed = True except QuitKeyboardInterrupt: pywikibot.output('\nUser quit {} bot run...' .format(self.__class__.__name__)) diff --git a/pywikibot/bot_choice.py b/pywikibot/bot_choice.py index 433acc1..4f2abe9 100755 --- a/pywikibot/bot_choice.py +++ b/pywikibot/bot_choice.py @@ -178,8 +178,8 @@ handled = option.handled(value) if handled is not None: return handled - else: - return super().handled(value) + + return super().handled(value)
def output(self): """Output the suboptions.""" diff --git a/pywikibot/comms/eventstreams.py b/pywikibot/comms/eventstreams.py index 053ce0e..eba15ef 100644 --- a/pywikibot/comms/eventstreams.py +++ b/pywikibot/comms/eventstreams.py @@ -10,7 +10,7 @@ *New in version 3.0.* """ # -# (C) Pywikibot team, 2017-2020 +# (C) Pywikibot team, 2017-2021 # # Distributed under the terms of the MIT license. # @@ -323,9 +323,9 @@ warning('Encountered error: {}'.format(event.data)) else: warning('Unknown event {} occurred.'.format(event.event)) - else: - debug('{}: Stopped iterating due to exceeding item limit.' - .format(self.__class__.__name__), _logger) + + debug('{}: Stopped iterating due to exceeding item limit.' + .format(self.__class__.__name__), _logger) del self.source
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index 576bcec..b822ede 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -1348,8 +1348,8 @@ action = err_msg.get(message) if action is True or action == self.action: return True - else: - return False + + return False
if isinstance(messages, dict): try: # behaviour before gerrit 124323 breaking change diff --git a/pywikibot/site/_apisite.py b/pywikibot/site/_apisite.py index b10743b..d0cabef 100644 --- a/pywikibot/site/_apisite.py +++ b/pywikibot/site/_apisite.py @@ -651,8 +651,8 @@ except KeyError: raise KeyError("No message '{}' found for lang '{}'" .format(key, amlang)) - else: - return result + + return result
return OrderedDict((key, _mw_msg_cache[amlang][key]) for key in keys)
@@ -1260,17 +1260,15 @@ for _from, _to in redirmap.items(): if _to['title'] in redirmap: raise CircularRedirectError(page) - else: - target = pywikibot.Page(source=page.site, title=target_title)
- # Check if target is on another site. - if target.site != page.site: - raise InterwikiRedirectPageError(page, target) - - # Redirect to Special: & Media: pages, which do not work - # like redirects, but are rendered like a redirect. - page._redirtarget = target - return page._redirtarget + target = pywikibot.Page(source=page.site, title=target_title) + # Check if target is on another site. + if target.site != page.site: + raise InterwikiRedirectPageError(page, target) + # Redirect to Special: & Media: pages, which do not work + # like redirects, but are rendered like a redirect. + page._redirtarget = target + return page._redirtarget
pagedata = list(result['query']['pages'].values())[0] # There should be only one value in 'pages' (the ultimate diff --git a/scripts/interwiki.py b/scripts/interwiki.py index 103fcc0..7af2748 100755 --- a/scripts/interwiki.py +++ b/scripts/interwiki.py @@ -2303,8 +2303,8 @@ self._next_page = page.title(with_ns=False) + '!' self._next_namespace = page.namespace() yield page - else: - self.restored_files.add(filename) + + self.restored_files.add(filename)
if self.opt.do_continue: yield from self.site.allpages(start=self.next_page, diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py index 95a1b83..fe3ece0 100644 --- a/tests/textlib_tests.py +++ b/tests/textlib_tests.py @@ -222,8 +222,8 @@ new = textlib.replaceCategoryInPlace(temp, dummy, cat, site=self.site) self.assertEqual(self.old, new) - else: - self.assertEqual(count, 3) + + self.assertEqual(count, 3)
# Testing removing categories temp = textlib.replaceCategoryInPlace(self.old, cats[0],