jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1293148?usp=email )

Change subject: doc/test: Update docstring for linter_pages Site method
......................................................................

doc/test: Update docstring for linter_pages Site method

- comma-separated string for pageids parameter never worked; remove
  it from the docstring.
- remove type annotation for lint_categories and pageids and move
  it to the method interface
- remove type checks and let API do this job
- add tests for pageids parameter

Bug: T427210
Change-Id: I62a448e92a1d078e82dd25204e26578c9c178620
---
M pywikibot/site/_extensions.py
M tests/linter_tests.py
2 files changed, 48 insertions(+), 24 deletions(-)

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




diff --git a/pywikibot/site/_extensions.py b/pywikibot/site/_extensions.py
index a5e32e8..a6dad3d 100644
--- a/pywikibot/site/_extensions.py
+++ b/pywikibot/site/_extensions.py
@@ -335,50 +335,44 @@
     @need_extension('Linter')
     def linter_pages(
         self: BaseSiteProtocol,
-        lint_categories=None,
+        lint_categories: Iterable[str] | str = None,
         total: int | None = None,
         namespaces=None,
-        pageids: str | int | None = None,
+        pageids: Iterable[str | int] | str | int | None = None,
         lint_from: str | int | None = None
     ) -> Iterable[pywikibot.Page]:
         """Return a generator to pages containing linter errors.

-        :param lint_categories: Categories of lint errors
-        :type lint_categories: An iterable that returns values (str), or
-            a pipe-separated string of values.
-        :param total: If not None, yielding this many items in total
-        :param namespaces: Only iterate pages in these namespaces
+        .. seealso:: https://www.mediawiki.org/wiki/Extension:Linter
+
+        :param lint_categories: Categories of lint errors. Must be an
+            iterable of lint categories, or a pipe-separated string of
+            lint categories.
+        :param total: If not None, yield this many items in total.
+        :param namespaces: Only iterate pages in these namespaces.
         :type namespaces: Iterable of str or Namespace key, or a single
             instance of those types. May be a '|' separated list of
             namespace identifiers.
         :param pageids: Only include lint errors from the specified
-            pageids
-        :type pageids: An iterable that returns pageids, or a comma- or
-             pipe-separated string of pageids (e.g. '945097,1483753,
-             956608' or '945097|483753|956608')
+            pageids. Must be given as an iterable of page ids, or a
+            pipe-separated string of page ids
+            (e.g. '945097|483753|956608').
         :param lint_from: Lint ID to start querying from
         :return: Pages with Linter errors.
         """
         query = self._generator(api.ListGenerator, type_arg='linterrors',
-                                total=total,  # Will set lntlimit
-                                namespaces=namespaces)
+                                total=total, namespaces=namespaces,
+                                lntfrom=lint_from)

         if lint_categories:
             if isinstance(lint_categories, str):
-                lint_categories = lint_categories.split('|')
-                lint_categories = [p.strip() for p in lint_categories]
-            query.request['lntcategories'] = '|'.join(lint_categories)
+                lint_categories = lint_categories.replace(' ', '')
+            query.request['lntcategories'] = lint_categories

         if pageids:
             if isinstance(pageids, str):
-                pageids = pageids.split('|')
-                pageids = [p.strip() for p in pageids]
-            # Validate pageids.
-            pageids = (str(int(p)) for p in pageids if int(p) > 0)
-            query.request['lntpageid'] = '|'.join(pageids)
-
-        if lint_from:
-            query.request['lntfrom'] = int(lint_from)
+                pageids = pageids.replace(' ', '')
+            query.request['lntpageid'] = pageids

         for pageitem in query:
             page = pywikibot.Page(self, pageitem['title'])
diff --git a/tests/linter_tests.py b/tests/linter_tests.py
index 713b29b..2b1bdf8 100755
--- a/tests/linter_tests.py
+++ b/tests/linter_tests.py
@@ -35,6 +35,36 @@
             self.assertIn(entry._lintinfo['category'],
                           ['obsolete-tag', 'missing-end-tag'])

+    def test_pageids(self) -> None:
+        """Test pageids parameter."""
+        for test, arg in {
+            'range': range(4711, 4750),
+            'list of strings': ['4715', '4716', '4717', '4718', '4718'],
+            'tuple of ints': (4715, 4716, 4717, 4718, 4718, 4719, 4720, 4721),
+            'pipe': '4715|4716|4717|4718|4718|4719|4720|4721|4722|4723|4724',
+            'pipe with spaces': '4715|4716 |4717| 4718|4718|4719|4720|4721',
+            'string': '4717',
+            'int': 4717,
+        }.items():
+            with self.subTest(arg=test):
+                le = list(self.site.linter_pages(pageids=arg))
+                for entry in le:
+                    self.assertIsInstance(entry, pywikibot.Page)
+                    info = entry._lintinfo
+                    self.assertIsInstance(info['lintId'], int)
+                    self.assertIsInstance(info['category'], str)
+                    self.assertIsInstance(info['location'], list)
+                    self.assertIsInstance(info['templateInfo'], dict)
+                    self.assertIsInstance(info['params'], dict)
+
+    def test_pageids_fail(self) -> None:
+        """Test wrong pageids parameter raises APIError."""
+        with self.assertRaisesRegex(
+            pywikibot.exceptions.APIError,
+            'Invalid value "4711-4750" for integer parameter "lntpageid"'
+        ):
+            list(self.site.linter_pages(pageids='4711-4750'))
+

 if __name__ == '__main__':
     with suppress(SystemExit):

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1293148?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I62a448e92a1d078e82dd25204e26578c9c178620
Gerrit-Change-Number: 1293148
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to