jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/590325 )
Change subject: [IMPR] Simplify generators
......................................................................
[IMPR] Simplify generators
Change-Id: I08e773599990174bd302819bed4ef971b1d9dde5
---
M pywikibot/page/__init__.py
M pywikibot/pagegenerators.py
M pywikibot/site/__init__.py
3 files changed, 27 insertions(+), 51 deletions(-)
Approvals:
Dvorapa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index f90adf4..5cdb83c 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -3548,8 +3548,7 @@
@param total: limit result to this number of pages.
@type total: int.
"""
- for item in self.contributions(total=total):
- yield item[0]
+ return (item[0] for item in self.contributions(total=total))
@deprecated_args(limit='total', namespace='namespaces')
def contributions(self, total=500, **kwargs):
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index 60faedb..d45c181 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -1384,9 +1384,8 @@
# defaults to namespace 0 because that's how Special:Newpages defaults
if site is None:
site = pywikibot.Site()
- for page, item in site.newpages(namespaces=namespaces, total=total,
- returndict=True):
- yield page
+ return (page for page, _ in site.newpages(namespaces=namespaces,
+ total=total, returndict=True))
@deprecated_args(nobots=None, step=None)
@@ -1493,15 +1492,13 @@
def InterwikiPageGenerator(page):
"""Iterate over all interwiki (non-language) links on a page."""
- for link in page.interwiki():
- yield pywikibot.Page(link)
+ return (pywikibot.Page(link) for link in page.interwiki())
@deprecated_args(step=None)
def LanguageLinksPageGenerator(page, total=None):
"""Iterate over all interwiki language links on a page."""
- for link in page.iterlanglinks(total=total):
- yield pywikibot.Page(link)
+ return (pywikibot.Page(link) for link in page.iterlanglinks(total=total))
@deprecated_args(step=None)
@@ -1732,9 +1729,7 @@
pywikibot.exception(e)
raise
- for page in generator:
- if page.namespace() in namespaces:
- yield page
+ return (page for page in generator if page.namespace() in namespaces)
@deprecated_args(ignoreList='ignore_list')
@@ -2283,10 +2278,8 @@
"""
if site is None:
site = pywikibot.Site()
- for entry in site.logevents(logtype='upload', total=total):
- # entry is an UploadEntry object
- # entry.page() returns a Page object
- yield entry.page()
+ return (entry.page()
+ for entry in site.logevents(logtype='upload', total=total))
def WikibaseItemGenerator(gen):
@@ -2359,8 +2352,7 @@
"""
if site is None:
site = pywikibot.Site()
- for page in site.unusedfiles(total=total):
- yield page
+ return site.unusedfiles(total=total)
@deprecated_args(number='total', repeat=None)
@@ -2374,8 +2366,7 @@
"""
if site is None:
site = pywikibot.Site()
- for page in site.withoutinterwiki(total=total):
- yield page
+ return site.withoutinterwiki(total=total)
@deprecated_args(number='total', repeat=None)
@@ -2390,8 +2381,7 @@
"""
if site is None:
site = pywikibot.Site()
- for page in site.uncategorizedcategories(total=total):
- yield page
+ return site.uncategorizedcategories(total=total)
@deprecated_args(number='total', repeat=None)
@@ -2406,8 +2396,7 @@
"""
if site is None:
site = pywikibot.Site()
- for page in site.uncategorizedimages(total=total):
- yield page
+ return site.uncategorizedimages(total=total)
@deprecated_args(number='total', repeat=None)
@@ -2422,8 +2411,7 @@
"""
if site is None:
site = pywikibot.Site()
- for page in site.uncategorizedpages(total=total):
- yield page
+ return site.uncategorizedpages(total=total)
@deprecated_args(number='total', repeat=None)
@@ -2438,8 +2426,7 @@
"""
if site is None:
site = pywikibot.Site()
- for page in site.uncategorizedtemplates(total=total):
- yield page
+ return site.uncategorizedtemplates(total=total)
@deprecated_args(number='total', repeat=None)
@@ -2454,8 +2441,7 @@
"""
if site is None:
site = pywikibot.Site()
- for page in site.lonelypages(total=total):
- yield page
+ return site.lonelypages(total=total)
@deprecated_args(number='total', repeat=None)
@@ -2470,8 +2456,7 @@
"""
if site is None:
site = pywikibot.Site()
- for page in site.unwatchedpages(total=total):
- yield page
+ return site.unwatchedpages(total=total)
def page_with_property_generator(name, total=None, site=None):
@@ -2517,8 +2502,7 @@
"""
if site is None:
site = pywikibot.Site()
- for page, timestamp in site.ancientpages(total=total):
- yield page
+ return (page for page, _ in site.ancientpages(total=total))
@deprecated_args(number='total', repeat=None)
@@ -2533,8 +2517,7 @@
"""
if site is None:
site = pywikibot.Site()
- for page in site.deadendpages(total=total):
- yield page
+ return site.deadendpages(total=total)
@deprecated_args(number='total', repeat=None)
@@ -2549,8 +2532,7 @@
"""
if site is None:
site = pywikibot.Site()
- for page, length in site.longpages(total=total):
- yield page
+ return (page for page, _ in site.longpages(total=total))
@deprecated_args(number='total', repeat=None)
@@ -2565,8 +2547,7 @@
"""
if site is None:
site = pywikibot.Site()
- for page, length in site.shortpages(total=total):
- yield page
+ return (page for page, _ in site.shortpages(total=total))
@deprecated_args(number='total')
@@ -2581,8 +2562,7 @@
"""
if site is None:
site = pywikibot.Site()
- for page in site.randompages(total=total, namespaces=namespaces):
- yield page
+ return site.randompages(total=total, namespaces=namespaces)
@deprecated_args(number='total')
@@ -2597,9 +2577,8 @@
"""
if site is None:
site = pywikibot.Site()
- for page in site.randompages(total=total, namespaces=namespaces,
- redirects=True):
- yield page
+ return site.randompages(total=total, namespaces=namespaces,
+ redirects=True)
@deprecated_args(link='url', euprotocol='protocol', step=None)
@@ -2636,8 +2615,7 @@
"""
if site is None:
site = pywikibot.Site()
- for page in site.search(query, total=total, namespaces=namespaces):
- yield page
+ return site.search(query, total=total, namespaces=namespaces)
def LiveRCPageGenerator(site=None, total=None):
@@ -3005,8 +2983,7 @@
repo = site.data_repository()
data = repo.search_entities(text, language, total=total)
- for item in data:
- yield pywikibot.ItemPage(repo, item['id'])
+ return (pywikibot.ItemPage(repo, item['id']) for item in data)
class PetScanPageGenerator(object):
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index fc016c2..bf3f1f5 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -2355,8 +2355,8 @@
if hasattr(notifications, 'values'):
notifications = notifications.values()
- for notification in notifications:
- yield Notification.fromJSON(self, notification)
+ return (Notification.fromJSON(self, notification)
+ for notification in notifications)
@need_extension('Echo')
def notifications_mark_read(self, **kwargs):
--
To view, visit https://gerrit.wikimedia.org/r/590325
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I08e773599990174bd302819bed4ef971b1d9dde5
Gerrit-Change-Number: 590325
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)