jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[tests] enable different types with BaseBot.treat()

Usually BaseBot.treat() works on BasePages and init_page has to be used
to upcast generators items to that type.

In some cases it can be usefull to allow generators item directly

Change-Id: Ide27f8cdce58558847c75fbe31e0589e2461e845
---
M pywikibot/bot.py
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 5c68925..ebabc53 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -1156,6 +1156,11 @@
Bot will process each page in the generator, invoking the method treat()
which must then be implemented by subclasses.

+ Each item processed by treat() must be a L{pywikibot.page.BasePage}
+ type. Use init_page() to upcast the type. To enable other types, set
+ BaseBot.treat_page_type to an appropriate type; your bot should
+ derive from BaseBot in that case and handle site properties.
+
If the subclass does not set a generator, or does not override
treat() or run(), NotImplementedError is raised.

@@ -1191,6 +1196,7 @@
self._save_counter = 0
self._skip_counter = 0
self._generator_completed = False
+ self.treat_page_type = pywikibot.page.BasePage # default type

@property
def current_page(self):
@@ -1475,9 +1481,11 @@
else:
page = initialized_page

- assert isinstance(page, pywikibot.page.BasePage), (
- '"page" is not a pywikibot.page.BasePage object but {}.'
- .format(page.__class__))
+ # validate page type
+ if not isinstance(page, self.treat_page_type):
+ raise TypeError('"page" is not a {!r} object but {}.'
+ .format(self.treat_page_type,
+ page.__class__.__name__))

if self.skip_page(page):
self._skip_counter += 1

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ide27f8cdce58558847c75fbe31e0589e2461e845
Gerrit-Change-Number: 676940
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: DannyS712 <dannys712.wiki@gmail.com>
Gerrit-MessageType: merged