jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] Don't stop iterators using StopIteration ......................................................................
[FIX] Don't stop iterators using StopIteration
With PEP 479 [1] it has been discouraged that a generator is stopped using `StopIteration`. Instead if should just return from the function or method. With 3.7 it'll convert that `StopIteration` into `RuntimeError` while 3.5 and 3.6 only issue deprecation warnings.
[1]: https://www.python.org/dev/peps/pep-0479/
Bug: T106224 Change-Id: I2743962594bc099dfeabc6f88d3654b178fb024d --- M pywikibot/pagegenerators.py M pywikibot/tools/__init__.py 2 files changed, 7 insertions(+), 4 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py index d9a4ead..2263ed5 100644 --- a/pywikibot/pagegenerators.py +++ b/pywikibot/pagegenerators.py @@ -1685,7 +1685,7 @@ while True: page_count = min(len(generator), step) if not page_count: - raise StopIteration + return
for page in PreloadingGenerator(generator, page_count): yield page diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py index ce07b8d..4ce740c 100644 --- a/pywikibot/tools/__init__.py +++ b/pywikibot/tools/__init__.py @@ -786,9 +786,12 @@ add = container_setitem
for item in iterable: - if (key(item) if key else item) not in container: - add(item) - yield item + try: + if (key(item) if key else item) not in container: + add(item) + yield item + except StopIteration: + return
class CombinedError(KeyError, IndexError):