Page MenuHomePhabricator

IsRedirectPageError.args does not match documentation
Closed, ResolvedPublicBUG REPORT

Description

The docs for BasePage.get() say:

pywikibot.exceptions.IsRedirectPageError – The page is a redirect. The argument of the exception is the title of the page it redirects to.

but that doesn't seem to be what's actually happening:

from pywikibot import Site, Page
from pywikibot.exceptions import IsRedirectPageError

site = Site("en")

page = Page(site, "Template:shortdescription")
try:
   print(page.get())
except IsRedirectPageError as ex:
   print(f"{ex.args=}")

prints

ex.args=(Page('Template:Shortdescription'),)

It's not clear if the docs are wrong or the code is wrong

Event Timeline

Xqt subscribed.

The old compat release documented the behaviour as

@exception IsRedirectPage The page is a redirect. The argument of the
                          exception is the title of the page it
                          redirects to.

and the exception was raised with the redirect target in Page._getEditPage() and Page._getEditPage():

m = self.site().redirectRegex().match(pagetext)
if m:
    # page text matches the redirect pattern
    if self.section() and "#" not in m.group(1):
        redirtarget = "%s#%s" % (m.group(1), self.section())
    else:
        redirtarget = m.group(1)
    if get_redirect:
        self._redirarg = redirtarget
    else:
        raise IsRedirectPage(redirtarget)

The core's implementation looks wrong then. On the other hand the core implementation was done 15 years ago in rPWBC1585a99.

Change #1016331 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] [doc] Update documentation forBasePage.get() and BasePage.text

https://gerrit.wikimedia.org/r/1016331

Change #1016331 merged by jenkins-bot:

[pywikibot/core@master] [doc] Update documentation for BasePage.get() and BasePage.text

https://gerrit.wikimedia.org/r/1016331