jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/826519 )

Change subject: [IMPR] use @staticmethod for several methods
......................................................................

[IMPR] use @staticmethod for several methods

Also replace BaseRevertBot.log by pywikibot.info
and use self.site in HarvestRobot.getTemplateSynonyms

Change-Id: I36a499bc40643f6cde88bc0f046829b2b945230e
---
M pywikibot/editor.py
M pywikibot/flow.py
M pywikibot/interwiki_graph.py
M pywikibot/throttle.py
M pywikibot/tools/djvu.py
M pywikibot/userinterfaces/gui.py
M pywikibot/userinterfaces/terminal_interface_base.py
M scripts/blockpageschecker.py
M scripts/category.py
M scripts/checkimages.py
M scripts/harvest_template.py
M scripts/interwiki.py
M scripts/patrol.py
M scripts/revertbot.py
M scripts/unusedfiles.py
M tests/aspects.py
M tests/harvest_template_tests.py
17 files changed, 51 insertions(+), 52 deletions(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/editor.py b/pywikibot/editor.py
index 7a16571..5cdf48a 100644
--- a/pywikibot/editor.py
+++ b/pywikibot/editor.py
@@ -28,7 +28,8 @@

     """Text editor."""

-    def _command(self, file_name: str, text: str,
+    @staticmethod
+    def _command(file_name: str, text: str,
                  jump_index: Optional[int] = None) -> List[str]:
         """Return editor selected in user-config.py."""
         if jump_index:
diff --git a/pywikibot/flow.py b/pywikibot/flow.py
index 71cc206..3f58475 100644
--- a/pywikibot/flow.py
+++ b/pywikibot/flow.py
@@ -89,7 +89,8 @@
             self._data = self.site.load_board(self)
         return self._data

-    def _parse_url(self, links: Mapping[str, Any]) -> Dict[str, Any]:
+    @staticmethod
+    def _parse_url(links: Mapping[str, Any]) -> Dict[str, Any]:
         """Parse a URL retrieved from the API."""
         if 'fwd' in links:
             rule = links['fwd']
diff --git a/pywikibot/interwiki_graph.py b/pywikibot/interwiki_graph.py
index 2149693..cf5c5d3 100644
--- a/pywikibot/interwiki_graph.py
+++ b/pywikibot/interwiki_graph.py
@@ -102,7 +102,8 @@
         self.graph = None  # type: Optional[pydot.Dot]
         self.subject = subject

-    def getLabel(self, page: 'pywikibot.page.Page') -> str:
+    @staticmethod
+    def getLabel(page: 'pywikibot.page.Page') -> str:
         """Get label for page."""
         return '"{}:{}"'.format(page.site.code, page.title())

diff --git a/pywikibot/throttle.py b/pywikibot/throttle.py
index c293493..9df3846 100644
--- a/pywikibot/throttle.py
+++ b/pywikibot/throttle.py
@@ -259,7 +259,8 @@

         self._write_file(processes)

-    def wait(self, seconds) -> None:
+    @staticmethod
+    def wait(seconds: Union[int, float]) -> None:
         """Wait for seconds seconds.

         Announce the delay if it exceeds a preset limit.
diff --git a/pywikibot/tools/djvu.py b/pywikibot/tools/djvu.py
index 85966da..136d43f 100644
--- a/pywikibot/tools/djvu.py
+++ b/pywikibot/tools/djvu.py
@@ -196,7 +196,8 @@
             self._get_page_info(force=force)
         return self._has_text

-    def _remove_control_chars(self, data):
+    @staticmethod
+    def _remove_control_chars(data):
         """Remove djvu format control characters.

         See http://djvu.sourceforge.net/doc/man/djvused.html for control chars.
diff --git a/pywikibot/userinterfaces/gui.py b/pywikibot/userinterfaces/gui.py
index b75ba4a..395b06f 100644
--- a/pywikibot/userinterfaces/gui.py
+++ b/pywikibot/userinterfaces/gui.py
@@ -67,7 +67,8 @@
         textcf.update(kwargs)
         super().__init__(master, **textcf)

-    def _initialize_config(self, Theme):
+    @staticmethod
+    def _initialize_config(Theme):
         """Fix idleConf.GetHighlight method for different Python releases."""
         config = {
             'padx': 5,
@@ -558,7 +559,8 @@
         self.description_field.grid(row=14, column=1, columnspan=3)
         self.description_scrollbar.grid(row=14, column=5)

-    def get_image(self, photo, width, height):
+    @staticmethod
+    def get_image(photo, width, height):
         """Take the BytesIO object and build an imageTK thumbnail."""
         if PYTHON_VERSION < (3, 6):
             # vulnerability found in Pillow<8.1.1
diff --git a/pywikibot/userinterfaces/terminal_interface_base.py 
b/pywikibot/userinterfaces/terminal_interface_base.py
index 91f3c11..3286355 100644
--- a/pywikibot/userinterfaces/terminal_interface_base.py
+++ b/pywikibot/userinterfaces/terminal_interface_base.py
@@ -540,7 +540,9 @@

                 self.stream_output('Error: Invalid response\n')

-    def editText(self, text: str, jumpIndex: Optional[int] = None,
+    @staticmethod
+    def editText(text: str,
+                 jumpIndex: Optional[int] = None,
                  highlight: Optional[str] = None) -> Optional[str]:
         """Return the text as edited by the user.

diff --git a/scripts/blockpageschecker.py b/scripts/blockpageschecker.py
index 60e7419..6e4828e 100755
--- a/scripts/blockpageschecker.py
+++ b/scripts/blockpageschecker.py
@@ -184,7 +184,8 @@
         'move': False,
     }

-    def invoke_editor(self, page) -> None:
+    @staticmethod
+    def invoke_editor(page) -> None:
         """Ask for an editor and invoke it."""
         choice = pywikibot.input_choice(
             'Do you want to open the page?',
diff --git a/scripts/category.py b/scripts/category.py
index 288b89b..cb04077 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -442,7 +442,8 @@
         self.always = False
         self.comment = comment

-    def sorted_by_last_name(self, catlink, pagelink) -> pywikibot.Page:
+    @staticmethod
+    def sorted_by_last_name(catlink, pagelink) -> pywikibot.Page:
         """Return a Category with key that sorts persons by their last name.

         Parameters: catlink - The Category to be linked.
@@ -452,7 +453,6 @@
         category_name is 'Author' and pl is a Page to [[Alexandre Dumas
         (senior)]], this function will return this Category:
         [[Category:Author|Dumas, Alexandre]].
-
         """
         page_name = pagelink.title()
         site = pagelink.site
@@ -1069,9 +1069,9 @@
         class CatIntegerOption(IntegerOption):
             """An option allowing a range of integers."""

-            def list_categories(self, cat_list, prefix: str = '') -> None:
-                """
-                Output categories in one or two columns.
+            @staticmethod
+            def list_categories(cat_list, prefix: str = '') -> None:
+                """Output categories in one or two columns.

                 Determine whether the list contains long or short
                 category titles and output category titles as enumerated
diff --git a/scripts/checkimages.py b/scripts/checkimages.py
index 0113c9b..b9ee55f 100755
--- a/scripts/checkimages.py
+++ b/scripts/checkimages.py
@@ -607,11 +607,8 @@
                     pywikibot.output(
                         'Another error... skipping the user...')

-    def upload_bot_change_function(
-        self,
-        report_page_text,
-        upload_bot_array
-    ) -> str:
+    @staticmethod
+    def upload_bot_change_function(report_page_text, upload_bot_array) -> str:
         """Detect the user that has uploaded the file through upload bot."""
         regex = upload_bot_array[1]
         results = re.findall(regex, report_page_text)
@@ -1316,7 +1313,8 @@
                                  % (self.image_name, self.license_found))
         return (self.license_found, self.white_templates_found)

-    def load(self, raw) -> List[str]:
+    @staticmethod
+    def load(raw) -> List[str]:
         """Load a list of objects from a string using regex."""
         list_loaded = []
         # I search with a regex how many user have not the talk page
diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py
index 54552af..36453ab 100755
--- a/scripts/harvest_template.py
+++ b/scripts/harvest_template.py
@@ -215,9 +215,9 @@
         self.cacheSources()
         self.templateTitles = self.getTemplateSynonyms(self.template_title)

-    def getTemplateSynonyms(self, title) -> List[str]:
+    def getTemplateSynonyms(self, title: str) -> List[str]:
         """Fetch redirects of the title, so we can check against them."""
-        temp = pywikibot.Page(pywikibot.Site(), title, ns=10)
+        temp = pywikibot.Page(self.site, title, ns=10)
         if not temp.exists():
             sys.exit('Template {} does not exist.'.format(temp.title()))

@@ -232,8 +232,8 @@
         titles.append(temp.title(with_ns=False))
         return titles

-    def template_link_target(self,
-                             item: pywikibot.ItemPage,
+    @staticmethod
+    def template_link_target(item: pywikibot.ItemPage,
                              site: pywikibot.site.BaseSite,
                              link_text: str) -> Optional[pywikibot.ItemPage]:
         """Find the ItemPage target for a given link text.
@@ -483,8 +483,9 @@
         for match in self.linkR.finditer(value):
             yield match.group('url')

-    def handle_commonsmedia(self, value, site, *args
-                            ) -> Iterator[pywikibot.FilePage]:
+    @staticmethod
+    def handle_commonsmedia(value, site,
+                            *args) -> Iterator[pywikibot.FilePage]:
         """Handle 'commonsMedia' claim type.

         .. versionadded:: 7.5
diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index f312393..6f9988d 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -1750,7 +1750,8 @@
                 break
         return True

-    def reportBacklinks(self, new, updatedSites) -> None:
+    @staticmethod
+    def reportBacklinks(new, updatedSites) -> None:
         """
         Report missing back links. This will be called from finish() if needed.

diff --git a/scripts/patrol.py b/scripts/patrol.py
index 004f823..e26aa52 100755
--- a/scripts/patrol.py
+++ b/scripts/patrol.py
@@ -52,7 +52,7 @@

 import pywikibot
 from pywikibot import pagegenerators
-from pywikibot.backports import removeprefix
+from pywikibot.backports import Container, removeprefix
 from pywikibot.bot import BaseBot, suggest_help


@@ -165,7 +165,8 @@
                 raise
             pywikibot.error(str(e))

-    def in_list(self, pagelist, title) -> bool:
+    @staticmethod
+    def in_list(pagelist: Container, title: str) -> bool:
         """Check if title present in pagelist."""
         verbose_output('Checking whitelist for: ' + title)

diff --git a/scripts/revertbot.py b/scripts/revertbot.py
index ea4a5d5..1fa571a 100755
--- a/scripts/revertbot.py
+++ b/scripts/revertbot.py
@@ -43,6 +43,7 @@

 import pywikibot
 from pywikibot import i18n
+from pywikibot.backports import Container
 from pywikibot.bot import OptionHandler
 from pywikibot.date import format_date, formatYear
 from pywikibot.exceptions import APIError, Error
@@ -81,13 +82,14 @@
             if callback(item):
                 result = self.revert(item)
                 if result:
-                    self.log('{}: {}'.format(item['title'], result))
+                    pywikibot.info('{}: {}'.format(item['title'], result))
                 else:
-                    self.log('Skipped {}'.format(item['title']))
+                    pywikibot.info('Skipped {}'.format(item['title']))
             else:
-                self.log('Skipped {} by callback'.format(item['title']))
+                pywikibot.info('Skipped {} by callback'.format(item['title']))

-    def callback(self, item) -> bool:
+    @staticmethod
+    def callback(item: Container) -> bool:
         """Callback function."""
         return 'top' in item

@@ -146,10 +148,6 @@
         pywikibot.exception(exc_info=False)
         return False

-    def log(self, msg) -> None:
-        """Log the message msg."""
-        pywikibot.output(msg)
-

 # for compatibility only
 myRevertBot = BaseRevertBot  # noqa: N816
diff --git a/scripts/unusedfiles.py b/scripts/unusedfiles.py
index c1a7584..82ad2f7 100755
--- a/scripts/unusedfiles.py
+++ b/scripts/unusedfiles.py
@@ -145,7 +145,8 @@
         self.current_page = page
         self.put_current(text)

-    def post_to_flow_board(self, page, post) -> None:
+    @staticmethod
+    def post_to_flow_board(page, post) -> None:
         """Post message as a Flow topic."""
         board = Board(page)
         header, rest = post.split('\n', 1)
diff --git a/tests/aspects.py b/tests/aspects.py
index 0a260ae..433c78a 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -181,7 +181,8 @@
         gen_titles = [page.title() for page in gen_pages]
         return gen_titles

-    def _get_canonical_titles(self, titles, site=None):
+    @staticmethod
+    def _get_canonical_titles(titles, site=None):
         if site:
             titles = [pywikibot.Link(title, site).canonical_title()
                       for title in titles]
diff --git a/tests/harvest_template_tests.py b/tests/harvest_template_tests.py
index 742b6f2..1d35e39 100644
--- a/tests/harvest_template_tests.py
+++ b/tests/harvest_template_tests.py
@@ -14,18 +14,6 @@
 from tests.aspects import ScriptMainTestCase


-class DummyBot:
-
-    """Dummy HarvestRobot."""
-
-    class current_page:  # noqa: D106, N801
-        pass
-
-    def __init__(self, site):  # noqa: D107
-        """Add a site object to current_page attribute."""
-        self.current_page.site = site
-
-
 class TestHarvestRobot(ScriptMainTestCase):

     """Test HarvestRobot."""
@@ -44,7 +32,7 @@
             with self.subTest(link=link, item=item):
                 dummy_item = ItemPage(self.site.data_repository(), 'Q1')
                 target = HarvestRobot.template_link_target(
-                    DummyBot(self.site), dummy_item, self.site, link)
+                    dummy_item, self.site, link)
                 self.assertIsInstance(target, ItemPage)
                 self.assertEqual(target.title(), item)


--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/826519
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: I36a499bc40643f6cde88bc0f046829b2b945230e
Gerrit-Change-Number: 826519
Gerrit-PatchSet: 5
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: Matěj Suchánek <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to