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

Change subject: site: Reuse watchlist page namespace
......................................................................

site: Reuse watchlist page namespace

Store each watchlist page namespace while filtering talk pages.
Reuse it for both the special-page and talk-page checks.

Change-Id: I44242c35be42e65d4085c385765c9f3a6af0fe78
---
M pywikibot/site/_generators.py
M tests/site_generators_tests.py
2 files changed, 20 insertions(+), 1 deletion(-)

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




diff --git a/pywikibot/site/_generators.py b/pywikibot/site/_generators.py
index b45c61d..6e35802 100644
--- a/pywikibot/site/_generators.py
+++ b/pywikibot/site/_generators.py
@@ -2549,7 +2549,7 @@
         def ignore_talkpages(page: pywikibot.page.BasePage) -> bool:
             """Ignore talk pages and special pages."""
             ns = page.namespace()
-            return ns >= 0 and not page.namespace() % 2
+            return ns >= 0 and not ns % 2

         expiry = None if force else pywikibot.config.API_config_expiry
         gen = api.PageGenerator(site=self, generator='watchlistraw',
diff --git a/tests/site_generators_tests.py b/tests/site_generators_tests.py
index 7ea52ee..0bfca57 100755
--- a/tests/site_generators_tests.py
+++ b/tests/site_generators_tests.py
@@ -94,6 +94,25 @@
         self.assertEqual(references, [backlink_c, backlink_a, embedded_b])


+class TestWatchedPages(DefaultSiteTestCase):
+
+    """Offline tests for Site.watched_pages."""
+
+    dry = True
+
+    def test_reuses_namespace(self) -> None:
+        """Test that watchlist filtering retrieves the namespace once."""
+        page = pywikibot.Page(self.site, 'Test page')
+        gen = self.site.watched_pages(with_talkpage=False)
+
+        with patch.object(page, 'namespace',
+                          wraps=page.namespace) as namespace:
+            result = gen._check_result_namespace(page)
+
+        self.assertTrue(result)
+        namespace.assert_called_once_with()
+
+
 class TestSiteGenerators(DefaultSiteTestCase):

     """Test cases for Site methods."""

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1324218?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: I44242c35be42e65d4085c385765c9f3a6af0fe78
Gerrit-Change-Number: 1324218
Gerrit-PatchSet: 1
Gerrit-Owner: Mahveotm <[email protected]>
Gerrit-Reviewer: JJMC89 <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to