jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/639589 )
Change subject: [IMPR] reduce code complexity of pagegenerators.py ......................................................................
[IMPR] reduce code complexity of pagegenerators.py
Change-Id: Ide9a5d1e93fa9149a109431075e827ed0456caa3 --- M pywikibot/pagegenerators.py 1 file changed, 20 insertions(+), 15 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py index 3bae2b5..5b45c62 100644 --- a/pywikibot/pagegenerators.py +++ b/pywikibot/pagegenerators.py @@ -1162,13 +1162,16 @@ value = None
handler = getattr(self, '_handle_' + arg[1:], None) - if handler: - handler_result = handler(value) - if isinstance(handler_result, bool): - return handler_result - if handler_result: - self.gens.append(handler_result) - return True + if not handler: + return False + + handler_result = handler(value) + if isinstance(handler_result, bool): + return handler_result + if handler_result: + self.gens.append(handler_result) + return True + return False
@@ -1480,14 +1483,16 @@ # inadvertently change pages on another wiki! yield pywikibot.Page(pywikibot.Link(linkmatch.group('title'), site)) - if linkmatch is None: - f.seek(0) - for title in f: - title = title.strip() - if '|' in title: - title = title[:title.index('|')] - if title: - yield pywikibot.Page(site, title) + if linkmatch is not None: + return + + f.seek(0) + for title in f: + title = title.strip() + if '|' in title: + title = title[:title.index('|')] + if title: + yield pywikibot.Page(site, title)
def PagesFromTitlesGenerator(iterable, site=None):