jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/641019 )
Change subject: [bugfix] Ensure that BaseBot.generator is a Generator ......................................................................
[bugfix] Ensure that BaseBot.generator is a Generator
Ensure that BaseBot.generator is a Generator that it can be closed with close method
Change-Id: I9961c67f3d6a94bde2d3100d7745948900700e6f --- M pywikibot/bot.py 1 file changed, 4 insertions(+), 0 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py index b2be383..0feab32 100644 --- a/pywikibot/bot.py +++ b/pywikibot/bot.py @@ -95,6 +95,7 @@ import warnings import webbrowser
+from collections.abc import Generator from contextlib import closing from importlib import import_module from pathlib import Path @@ -1468,6 +1469,9 @@ if not hasattr(self, 'generator'): raise NotImplementedError('Variable {}.generator not set.' .format(self.__class__.__name__)) + if not isinstance(self.generator, Generator): + # to provide close() method + self.generator = (item for item in self.generator) try: for item in self.generator: # preprocessing of the page
pywikibot-commits@lists.wikimedia.org