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

Change subject: [IMPR] use Page.text instead of Page.get() to get the page 
content.
......................................................................

[IMPR] use Page.text instead of Page.get() to get the page content.

Page.text already gives an emtpy string if the page does not exists.

Change-Id: I4c2848cae22df5304f937ce438e9887171e92e16
---
M pywikibot/page/_page.py
1 file changed, 8 insertions(+), 14 deletions(-)

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




diff --git a/pywikibot/page/_page.py b/pywikibot/page/_page.py
index 2154ea9..991a985 100644
--- a/pywikibot/page/_page.py
+++ b/pywikibot/page/_page.py
@@ -125,21 +125,20 @@
     @deprecated_args(botflag='bot')  # since 9.3.0
     def set_redirect_target(
         self,
-        target_page,
+        target_page: pywikibot.Page | str,
         create: bool = False,
         force: bool = False,
         keep_section: bool = False,
         save: bool = True,
         **kwargs
     ):
-        """
-        Change the page's text to point to the redirect page.
+        """Change the page's text to point to the redirect page.

         .. versionchanged:: 9.3
            *botflag* keyword parameter was renamed to *bot*.

-        :param target_page: target of the redirect, this argument is required.
-        :type target_page: pywikibot.Page or string
+        :param target_page: target of the redirect, this argument is
+            required.
         :param create: if true, it creates the redirect even if the page
             doesn't exist.
         :param force: if true, it set the redirect target even the page
@@ -147,8 +146,8 @@
         :param keep_section: if the old redirect links to a section
             and the new one doesn't it uses the old redirect's section.
         :param save: if true, it saves the page immediately.
-        :param kwargs: Arguments which are used for saving the page directly
-            afterwards, like 'summary' for edit summary.
+        :param kwargs: Arguments which are used for saving the page
+            directly afterwards, like *summary* for edit summary.
         """
         if isinstance(target_page, str):
             target_page = pywikibot.Page(self.site, target_page)
@@ -161,13 +160,8 @@
         if self.exists() and not self.isRedirectPage() and not force:
             raise IsNotRedirectPageError(self)

-        redirect_regex = self.site.redirect_regex
-        if self.exists():
-            old_text = self.get(get_redirect=True)
-        else:
-            old_text = ''
-
-        result = redirect_regex.search(old_text)
+        old_text = self.text
+        result = self.site.redirect_regex.search(old_text)
         if result:
             oldlink = result[1]
             if (keep_section and '#' in oldlink

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1053359?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: I4c2848cae22df5304f937ce438e9887171e92e16
Gerrit-Change-Number: 1053359
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <i...@gno.de>
Gerrit-Reviewer: Xqt <i...@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: AnotherLadsgroup <ladsgr...@gmail.com>
_______________________________________________
Pywikibot-commits mailing list -- pywikibot-commits@lists.wikimedia.org
To unsubscribe send an email to pywikibot-commits-le...@lists.wikimedia.org

Reply via email to