JJMC89 has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/699729 )
Change subject: [IMPR] Add update_options attribute to update available_options ......................................................................
[IMPR] Add update_options attribute to update available_options
With update_options it is not necessary to have an instance initializer which only updates available_options and calls super().__init__()
Change-Id: I8c9a92adf4be4b29f69ee3723ab81054328be351 --- M pywikibot/bot.py M scripts/add_text.py M scripts/basic.py M scripts/commonscat.py M scripts/cosmetic_changes.py M scripts/fixing_redirects.py M scripts/misspelling.py 7 files changed, 19 insertions(+), 54 deletions(-)
Approvals: jenkins-bot: Verified JJMC89: Looks good to me, approved
diff --git a/pywikibot/bot.py b/pywikibot/bot.py index 7c038a2..7dc13bd 100644 --- a/pywikibot/bot.py +++ b/pywikibot/bot.py @@ -1192,6 +1192,9 @@ 'always': False, # By default ask for confirmation when putting a page }
+ # update_options can be used to update available_options + update_options = {} + _current_page = None
def __init__(self, **kwargs): @@ -1207,6 +1210,7 @@ else: self.generator = kwargs.pop('generator')
+ self.available_options.update(self.update_options) super().__init__(**kwargs)
self._treat_counter = 0 diff --git a/scripts/add_text.py b/scripts/add_text.py index f565538..bd0aebc 100755 --- a/scripts/add_text.py +++ b/scripts/add_text.py @@ -302,11 +302,7 @@ """A bot which adds a text to a page."""
summary_key = 'add_text-adding' - - def __init__(self, **kwargs): - """Initializer.""" - self.available_options.update(DEFAULT_ARGS) - super().__init__(**kwargs) + update_options = DEFAULT_ARGS
@property def summary_parameters(self): diff --git a/scripts/basic.py b/scripts/basic.py index 096d2e4..8270def 100755 --- a/scripts/basic.py +++ b/scripts/basic.py @@ -87,25 +87,12 @@
summary_key = 'basic-changing'
- def __init__(self, **kwargs) -> None: - """ - Initializer. - - :keyword generator: the page generator that determines on which pages - to work. BasicBot assigns it to self.generator attribute. - :type generator: generator - """ - # Add your own options to the bot and set their defaults - # -always option is predefined by BaseBot class - self.available_options.update({ - 'replace': False, # delete old text and write the new text - 'summary': None, # your own bot summary - 'text': 'Test', # add this text from option. 'Test' is default - 'top': False, # append text on top of the page - }) - - # call initializer of the super class - super().__init__(**kwargs) + update_options = { + 'replace': False, # delete old text and write the new text + 'summary': None, # your own bot summary + 'text': 'Test', # add this text from option. 'Test' is default + 'top': False, # append text on top of the page + }
def treat_page(self) -> None: """Load the given page, do some changes, and save it.""" diff --git a/scripts/commonscat.py b/scripts/commonscat.py index db53634..6bc5efe 100755 --- a/scripts/commonscat.py +++ b/scripts/commonscat.py @@ -226,12 +226,7 @@
"""Commons categorisation bot."""
- def __init__(self, **kwargs): - """Initializer.""" - self.available_options.update({ - 'summary': None, - }) - super().__init__(**kwargs) + update_options = {'summary': None}
def skip_page(self, page): """Skip category redirects or disambigs.""" diff --git a/scripts/cosmetic_changes.py b/scripts/cosmetic_changes.py index daeb1a7..2eece60 100755 --- a/scripts/cosmetic_changes.py +++ b/scripts/cosmetic_changes.py @@ -66,15 +66,11 @@ """Cosmetic changes bot."""
summary_key = 'cosmetic_changes-standalone' - - def __init__(self, **kwargs) -> None: - """Initializer.""" - self.available_options.update({ - 'async': False, - 'summary': '', - 'ignore': CANCEL.MATCH, - }) - super().__init__(**kwargs) + update_options = { + 'async': False, + 'summary': '', + 'ignore': CANCEL.MATCH, + }
def treat_page(self) -> None: """Treat page with the cosmetic toolkit.""" diff --git a/scripts/fixing_redirects.py b/scripts/fixing_redirects.py index c2dfa81..5930dcf 100755 --- a/scripts/fixing_redirects.py +++ b/scripts/fixing_redirects.py @@ -58,14 +58,7 @@ ignore_save_related_errors = True ignore_server_errors = True summary_key = 'fixing_redirects-fixing' - - def __init__(self, **kwargs) -> None: - """Initializer.""" - self.available_options.update({ - 'overwrite': False, - }) - - super().__init__(**kwargs) + update_options = {'overwrite': False}
def replace_links(self, text, linkedPage, targetPage): """Replace all source links by target.""" diff --git a/scripts/misspelling.py b/scripts/misspelling.py index a16e26f..0928b58 100755 --- a/scripts/misspelling.py +++ b/scripts/misspelling.py @@ -54,13 +54,7 @@
# Optional: if there is a category, one can use the -start parameter misspelling_categories = ('Q8644265', 'Q9195708') - - def __init__(self, **kwargs) -> None: - """Initializer.""" - self.available_options.update({ - 'start': None, - }) - super().__init__(**kwargs) + update_options = {'start': None}
@property def generator(self) -> Generator[pywikibot.Page, None, None]: