jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/426819 )
Change subject: [PEP 479] Change StopIteration handling inside generators
......................................................................
[PEP 479] Change StopIteration handling inside generators
User.uploadedImages:
just return instead of raising StopIteration
interwiki.generateMore:
StopIteration was raised only to leave the the outer for loop.
Implement a more suitable way to escape from that loop:
Use for loop for the pageGenerator which stops looping if the generator
is empty. In that case the outer for loop could be finished. set
self.pageGenerator to None then.
The IOError is from old compat code which used their
TextfileGenerator to retrieve pages from the text file. Now pickle is
used and IOError is handled when loading from file.
https://www.python.org/dev/peps/pep-0479/#why-not-fix-all-next-methods
Change-Id: Ic342346698d01f8dd0050a2558e689edaebdfb6c
---
M pywikibot/page.py
M scripts/interwiki.py
2 files changed, 51 insertions(+), 53 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 97c6681..b5b0396 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -3589,9 +3589,8 @@
@type total: int
"""
if not self.isRegistered():
- raise StopIteration
- for item in self.logevents(
- logtype='upload', total=total):
+ return
+ for item in self.logevents(logtype='upload', total=total):
yield (item.page(),
unicode(item.timestamp()),
item.comment(),
diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index 8235e14..0333585 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -2063,60 +2063,59 @@
'NOTE: Number of pages queued is {0}, trying to add {1} more.'
.format(len(self.subjects), number))
for i in range(number):
- try:
- while True:
+ for page in self.pageGenerator:
+ if page in self.conf.skip:
+ pywikibot.output('Skipping: {0} is in the skip list'
+ .format(page))
+ continue
+ if self.conf.skipauto:
+ dictName, year = page.autoFormat()
+ if dictName is not None:
+ pywikibot.output(
+ 'Skipping: {0} is an auto entry {1}({2})'
+ .format(page, dictName, year))
+ continue
+ if self.conf.parenthesesonly:
+ # Only yield pages that have ( ) in titles
+ if '(' not in page.title():
+ continue
+ if page.isTalkPage():
+ pywikibot.output('Skipping: {} is a talk page'
+ .format(page))
+ continue
+ if page.namespace() == 10:
try:
- page = next(self.pageGenerator)
- except IOError:
- pywikibot.output(u'IOError occurred; skipping')
+ tmpl, loc = moved_links[page.site.code]
+ del tmpl
+ except KeyError:
+ loc = None
+ if loc is not None and loc in page.title():
+ pywikibot.output(
+ 'Skipping: {} is a templates subpage'
+ .format(page.title()))
continue
- if page in self.conf.skip:
- pywikibot.output('Skipping: {0} is in the skip list'
- .format(page))
- continue
- if self.conf.skipauto:
- dictName, year = page.autoFormat()
- if dictName is not None:
- pywikibot.output(
- 'Skipping: {0} is an auto entry {1}({2})'
- .format(page, dictName, year))
- continue
- if self.conf.parenthesesonly:
- # Only yield pages that have ( ) in titles
- if "(" not in page.title():
- continue
- if page.isTalkPage():
- pywikibot.output(u'Skipping: %s is a talk page' % page)
- continue
- if page.namespace() == 10:
- try:
- tmpl, loc = moved_links[page.site.code]
- del tmpl
- except KeyError:
- loc = None
- if loc is not None and loc in page.title():
- pywikibot.output(
- 'Skipping: %s is a templates subpage'
- % page.title())
- continue
+ break
+ else: # generator stopped
+ break
+
+ if self.generateUntil:
+ until = self.generateUntil
+ page_namespace = (
+ page.site.namespaces[int(page.namespace())])
+ if page_namespace.case == 'first-letter':
+ until = first_upper(until)
+ if page.title(withNamespace=False) > until:
break
- if self.generateUntil:
- until = self.generateUntil
- page_namespace = (
- page.site.namespaces[int(page.namespace())])
- if page_namespace.case == 'first-letter':
- until = first_upper(until)
- if page.title(withNamespace=False) > until:
- raise StopIteration
- self.add(page, hints=self.conf.hints)
- self.generated += 1
- if self.generateNumber:
- if self.generated >= self.generateNumber:
- raise StopIteration
- except StopIteration:
- self.pageGenerator = None
- break
+ self.add(page, hints=self.conf.hints)
+ self.generated += 1
+ if self.generateNumber:
+ if self.generated >= self.generateNumber:
+ break
+ else:
+ return
+ # for loop was exited by break statement
+ self.pageGenerator = None
def firstSubject(self):
"""Return the first subject that is still being worked
on."""
--
To view, visit
https://gerrit.wikimedia.org/r/426819
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic342346698d01f8dd0050a2558e689edaebdfb6c
Gerrit-Change-Number: 426819
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>