jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/700931 )
Change subject: [bugfix] Don't use update_options if a bot is to be subclassed
......................................................................
[bugfix] Don't use update_options if a bot is to be subclassed
A bot class can only have one update_options class attribute.
this must not be overridden if a bot class is derived from another.
Use available_options.update() in initializer for the parent class
in such case.
Bug: T285315
Change-Id: I5ae9d5646963dd43e9bee04f0266a304cecf8466
---
M pywikibot/bot.py
M pywikibot/specialbots/_unlink.py
M scripts/image.py
M scripts/noreferences.py
M scripts/replace.py
5 files changed, 26 insertions(+), 23 deletions(-)
Approvals:
JJMC89: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index b854ed7..afac80c 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -1205,7 +1205,9 @@
'always': False, # By default ask for confirmation when putting a page
}
- # update_options can be used to update available_options
+ # update_options can be used to update available_options;
+ # do not use it if the bot class is to be derived but use
+ # self.available_options.update(<dict>) initializer in such case
update_options = {}
_current_page = None
diff --git a/pywikibot/specialbots/_unlink.py b/pywikibot/specialbots/_unlink.py
index ca0c114..56a6d93 100644
--- a/pywikibot/specialbots/_unlink.py
+++ b/pywikibot/specialbots/_unlink.py
@@ -60,11 +60,14 @@
"""A basic bot unlinking a given link from the current
page."""
- update_options = {
- 'namespaces': [],
- # Which namespaces should be processed?
- # default to [] which means all namespaces will be processed
- }
+ def __init__(self, **kwargs):
+ """Redirect all parameters and add namespace as an available
option."""
+ self.available_options.update({
+ 'namespaces': [],
+ # Which namespaces should be processed?
+ # default to [] which means all namespaces will be processed
+ })
+ super().__init__(**kwargs)
def _create_callback(self):
"""Create a new callback instance for
replace_links."""
diff --git a/scripts/image.py b/scripts/image.py
index bad0300..76e30ea 100755
--- a/scripts/image.py
+++ b/scripts/image.py
@@ -54,11 +54,6 @@
"""This bot will replace or remove all occurrences of an old
image."""
- update_options = {
- 'summary': '',
- 'loose': False,
- }
-
def __init__(self, generator, old_image: str,
new_image: Optional[str] = None, **kwargs):
"""
@@ -70,6 +65,11 @@
:param new_image: the title of the new image (without namespace), or
None if you want to remove the image
"""
+ self.available_options.update({
+ 'summary': None,
+ 'loose': False,
+ })
+
SingleSiteBot.__init__(self, generator=generator, **kwargs)
self.old_image = old_image
diff --git a/scripts/noreferences.py b/scripts/noreferences.py
index cfc59ad..69692bf 100755
--- a/scripts/noreferences.py
+++ b/scripts/noreferences.py
@@ -516,13 +516,12 @@
"""References section bot."""
- update_options = {
- 'verbose': True,
- }
-
@remove_last_args(['gen'])
def __init__(self, **kwargs) -> None:
"""Initializer."""
+ self.available_options.update({
+ 'verbose': True,
+ })
super().__init__(**kwargs)
self.refR = _ref_regex
diff --git a/scripts/replace.py b/scripts/replace.py
index 000c8f1..f558502 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -522,17 +522,16 @@
about the missing site
"""
- update_options = {
- 'addcat': None,
- 'allowoverlap': False,
- 'recursive': False,
- 'sleep': 0.0,
- 'summary': '',
- }
-
@deprecated_args(acceptall='always', addedCat='addcat')
def __init__(self, generator, replacements, exceptions=None, **kwargs):
"""Initializer."""
+ self.available_options.update({
+ 'addcat': None,
+ 'allowoverlap': False,
+ 'recursive': False,
+ 'sleep': 0.0,
+ 'summary': None,
+ })
super().__init__(generator=generator, **kwargs)
for i, replacement in enumerate(replacements):
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/700931
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I5ae9d5646963dd43e9bee04f0266a304cecf8466
Gerrit-Change-Number: 700931
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-MessageType: merged