Xqt has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1356612?usp=email )

Change subject: pagegenerators: Include redirects in -ref
......................................................................

pagegenerators: Include redirects in -ref

Include redirect and non-redirect references so -redirect can perform
the final filtering.

Allow getReferences() to accept None and add a regression test.

Bug: T419512
Change-Id: I73f6e2880dac0e39a7da6ead8856932b5d5df234
---
M pywikibot/page/_basepage.py
M pywikibot/pagegenerators/_factory.py
M tests/pagegenerators_tests.py
3 files changed, 16 insertions(+), 3 deletions(-)

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




diff --git a/pywikibot/page/_basepage.py b/pywikibot/page/_basepage.py
index d0434d5..3b4538d 100644
--- a/pywikibot/page/_basepage.py
+++ b/pywikibot/page/_basepage.py
@@ -1176,7 +1176,7 @@
                       follow_redirects: bool = True,
                       with_template_inclusion: bool = True,
                       only_template_inclusion: bool = False,
-                      filter_redirects: bool = False,
+                      filter_redirects: bool | None = False,
                       namespaces=None,
                       total: int | None = None,
                       content: bool = False) -> Iterable[pywikibot.Page]:
@@ -1195,7 +1195,8 @@
             is used as a template.
         :param only_template_inclusion: If True, only iterate pages where self
             is used as a template.
-        :param filter_redirects: If True, only iterate redirects to self.
+        :param filter_redirects: If True, only iterate redirects; if False,
+            omit redirects; if None, do not filter.
         :param namespaces: Only iterate pages in these namespaces
         :param total: Iterate no more than this number of unique pages in total
         :param content: If True, retrieve the content of the current version
diff --git a/pywikibot/pagegenerators/_factory.py 
b/pywikibot/pagegenerators/_factory.py
index a455a99..6103ff4 100644
--- a/pywikibot/pagegenerators/_factory.py
+++ b/pywikibot/pagegenerators/_factory.py
@@ -756,7 +756,7 @@
             value = pywikibot.input(
                 'Links to which page should be processed?')
         page = pywikibot.Page(pywikibot.Link(value, self.site))
-        return page.getReferences()
+        return page.getReferences(filter_redirects=None)

     def _handle_links(self, value: str) -> HANDLER_GEN_TYPE:
         """Handle `-links` argument."""
diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py
index f4b64be..1328af8 100755
--- a/tests/pagegenerators_tests.py
+++ b/tests/pagegenerators_tests.py
@@ -856,6 +856,18 @@

     dry = True

+    def test_ref_includes_redirects(self) -> None:
+        """Test -ref generator includes redirects before filtering."""
+        gf = pagegenerators.GeneratorFactory(site=self.get_site())
+        with mock.patch.object(
+                pywikibot.Page, 'getReferences', autospec=True,
+                return_value=iter(())
+        ) as get_references:
+            self.assertTrue(gf.handle_arg('-ref:Main Page'))
+
+        get_references.assert_called_once_with(
+            mock.ANY, filter_redirects=None)
+
     def test_title_filters_run_before_redirect_filter(self) -> None:
         """Test title filters discard pages before redirect checks."""
         site = self.get_site()

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1356612?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: I73f6e2880dac0e39a7da6ead8856932b5d5df234
Gerrit-Change-Number: 1356612
Gerrit-PatchSet: 3
Gerrit-Owner: Tomlu60220244 <[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