Page MenuHomePhabricator

Pywikibot tests fails with Python 3.12
Closed, ResolvedPublicBUG REPORT

Description

Pywikibot tests fails with Python 3.12. The reason is that itertools.batched() is used instead of the old pywkibot.itertools.itergroups() implementation but batched needs a int value for the group lenght whereas itergroups also works with NoneType as a side effect. As a result _paraminfo.fetch fails.

======================================================================
ERROR: setUpClass (tests.site_login_logout_tests.TestClearCookies)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/pywikibot/pywikibot/tests/aspects.py", line 601, in setUpClass
    site.login()
  File "/home/runner/work/pywikibot/pywikibot/pywikibot/site/_apisite.py", line 412, in login
    if login_manager.login(retry=True, autocreate=autocreate):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/pywikibot/pywikibot/pywikibot/login.py", line 294, in login
    self.login_to_site()
  File "/home/runner/work/pywikibot/pywikibot/pywikibot/login.py", line 392, in login_to_site
    parameters = self._login_parameters(
                 ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/pywikibot/pywikibot/pywikibot/login.py", line 350, in _login_parameters
    token = self.site.tokens['login']
            ~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/runner/work/pywikibot/pywikibot/pywikibot/site/_tokenwallet.py", line 45, in __getitem__
    self._tokens = self.site.get_tokens([])
                   ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/pywikibot/pywikibot/pywikibot/site/_apisite.py", line 1614, in get_tokens
    pdata = self._paraminfo.parameter('query+tokens', 'type')
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/pywikibot/pywikibot/pywikibot/data/api/_paraminfo.py", line 483, in parameter
    module = self[module]
             ~~~~^^^^^^^^
  File "/home/runner/work/pywikibot/pywikibot/pywikibot/data/api/_paraminfo.py", line 442, in __getitem__
    self.fetch({key})
  File "/home/runner/work/pywikibot/pywikibot/pywikibot/data/api/_paraminfo.py", line 174, in fetch
    self._init()
  File "/home/runner/work/pywikibot/pywikibot/pywikibot/data/api/_paraminfo.py", line 108, in _init
    self._fetch(self.preloaded_modules)
  File "/home/runner/work/pywikibot/pywikibot/pywikibot/data/api/_paraminfo.py", line 222, in _fetch
    for module_batch in module_generator():
  File "/home/runner/work/pywikibot/pywikibot/pywikibot/data/api/_paraminfo.py", line 198, in module_generator
    for batch in batched(sorted(modules), self._limit):
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object cannot be interpreted as an integer

Event Timeline

Xqt changed the task status from Open to In Progress.Jun 28 2023, 8:44 AM
Xqt triaged this task as High priority.
Xqt changed the subtype of this task from "Task" to "Bug Report".

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

[pywikibot/core@master] [bugfix] Use 50 as default ParamInfo._limit for the first call

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

Change 933865 merged by jenkins-bot:

[pywikibot/core@master] [bugfix] Use 50 as default ParamInfo._limit for the first call

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