Page MenuHomePhabricator

NoRedirectPageBot: Two conflicting messages
Closed, ResolvedPublicBUG REPORT

Description

WARNING: /.../python/pywikibot/pywikibot/bot.py:1787: FutureWarning: RedirectPageBot is deprecated since release 7.2.0; use BaseBot attribute 'use_redirects = False' instead.
  super().__init__(**kwargs)

WARNING: use_redirects is not a valid option. It was ignored.

That's what I got when I did the two, also import NoRedirectPageBot from pywikibot.bot and also use the parameter.
The bot is also subclass of SingleSiteBot and ExistingPageBot (maybe the warning is because one of them...)

Event Timeline

Version:

Pywikibot: pywikibot/__init__.py (, -1 (unknown), 2022/07/23, 15:01:36, UNKNOWN)
Release version: 7.5.0
setuptools version: 58.2.0
mwparserfromhell version: 0.6.3
wikitextparser version: n/a
requests version: 2.26.0
Python: 3.9.7 (default, Oct  6 2021, 01:34:26)
[GCC 11.1.0]

I could reproduce it as follows:

D:\pwb\GIT\core>pwb basic -simulate -use_redirects -page:User:Xqt
WARNING: D:\pwb\GIT\core\pywikibot\bot.py:1826: FutureWarning: RedirectPageBot is deprecated since release 7.2.0; use BaseBot attribute 'use_redirects = False' instead.
  super().__init__(**kwargs)

WARNING: use_redirects is not a valid option. It was ignored.

The deprecation warning intends no longer use NoRedirectPageBot class but the no_redirect attribute; this is not meant as an -no_redirect option. An example how this works can be seen at basic.py: Basic bot is declared as

class BasicBot(
    # Refer pywikobot.bot for generic bot classes
    SingleSiteBot,  # A bot only working on one site
    ConfigParserBot,  # A bot which reads options from scripts.ini setting file
    # CurrentPageBot,  # Sets 'current_page'. Process it in treat_page method.
    #                  # Not needed here because we have subclasses
    ExistingPageBot,  # CurrentPageBot which only treats existing pages
    AutomaticTWSummaryBot,  # Automatically defines summary; needs summary_key
):

    use_redirects = False  # treats non-redirects only

The use_redirects = False is the important part which ensures that redirects are skipped.

See also: https://doc.wikimedia.org/pywikibot/master/api_ref/bot.html#bot.BaseBot.use_redirects

Anyway there is a remaining issue due to the deprecation warning message which should be FutureWarning: NoRedirectPageBot is deprecated...

Xqt changed the task status from Open to In Progress.Dec 25 2022, 9:56 AM
Xqt claimed this task.
Xqt triaged this task as Medium priority.

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

[pywikibot/core@master] [fix] Fix deprecation warning for NoRedirectPageBot class

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

Change 871288 merged by jenkins-bot:

[pywikibot/core@master] [fix] Fix deprecation warning for NoRedirectPageBot class

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

Thank you @Xqt, I thought that it supposed to pass as a parameter to super().__init__(**kwargs). What caused my wrong is a line that tell this (the last line of the first warning)... What's the meaning of this line?

Thank you @Xqt, I thought that it supposed to pass as a parameter to super().__init__(**kwargs). What caused my wrong is a line that tell this (the last line of the first warning)... What's the meaning of this line?

line 1787 (or 1826 in version 8.0) is just the traceback line which caused the deprecation warning but depends on the stack level (https://docs.python.org/3/library/warnings.html?highlight=warn#warnings.warn). There is no other meaning with it.