jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[IMPR] Make BaseBot._generator_completed a public attribute

generator_completed can be used inside scripts e.g. in teardown method.

- rename _generator_completed to generator_completed
- update category.py
- add documtentation and an example for this attribute

Change-Id: I48eac33feab0d24cadfa30de6250631ba3dd74cb
---
M pywikibot/bot.py
M scripts/category.py
2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 70e845d..ebe226b 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -1279,7 +1279,7 @@
else:
#: instance variable to hold the generator processed by
#: :meth:`run` method
- self.generator = kwargs.pop('generator')
+ self.generator = kwargs.pop('generator') # type: Iterable

self.available_options.update(self.update_options)
super().__init__(**kwargs)
@@ -1295,7 +1295,19 @@
Your additional counters are also printed during :meth:`exit`
"""

- self._generator_completed = False
+ self.generator_completed = False # type: bool
+ """Instance attribute which is True if the generator is completed.
+
+ To check for an empty generator you may use::
+
+ if self.generator_completed and not self.counter['read']:
+ print('generator was emtpty')
+
+ .. note:: An empty generator remains False.
+ .. versionadded:: 3.0
+ .. versionchanged:: 7.4
+ renamed to `generator_completed` to become a public attribute.
+ """

#: instance variable to hold the default page type
self.treat_page_type = pywikibot.page.BasePage # type: Any
@@ -1643,7 +1655,7 @@
self.counter['read'] += 1
self.treat(page)

- self._generator_completed = True
+ self.generator_completed = True
except QuitKeyboardInterrupt:
pywikibot.output('\nUser quit {} bot run...'
.format(self.__class__.__name__))
diff --git a/scripts/category.py b/scripts/category.py
index 8db8a1d..360c779 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -1240,7 +1240,7 @@

def teardown(self) -> None:
"""Cleanups after run operation."""
- if self._generator_completed and not self.counter['read']:
+ if self.generator_completed and not self.counter['read']:
pywikibot.output('There are no pages or files in category {}.'
.format(self.cat_title))


To view, visit change 800891. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I48eac33feab0d24cadfa30de6250631ba3dd74cb
Gerrit-Change-Number: 800891
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-Reviewer: Dalba <dalba.wiki@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged