Page MenuHomePhabricator

site.interwiki_prefix() method always fails
Closed, ResolvedPublic

Description

>>> import pwb, pywikibot as py
>>> s = py.Site()
>>> x = s.interwiki_prefix(s)

Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    x = s.interwiki_prefix(s)
  File "pywikibot\site.py", line 969, in interwiki_prefix
    prefixes.update(self._interwikimap.get_by_url(url))
  File "pywikibot\site.py", line 712, in get_by_url
    return set(prefix for prefix, iw_entry in self._iw_sites
  File "pywikibot\site.py", line 713, in <genexpr>
    if iw_entry.url == url)
AttributeError: 'unicode' object has no attribute 'url'

Seems it was never used in 3,5 years.

Event Timeline

Xqt triaged this task as Low priority.Feb 24 2018, 4:45 PM

I noticed Pywikibot family reached 1000 currently openned tasks recently (currently showing this task as 1000th)! 🎉🎉🎉
(I wish the number of currently openned tasks was smaller)

Well there are some tasks which can be closed soon after reviewing patches. A patch for this comes soon ;)

Change 414116 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [bugfix] Fix for _InterwikiMap.get_by_url() and interwiki_prefix()

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

Now we have another but:

>>> import pywikibot
>>> s = pywikibot.Site()
>>> x = s.interwiki_prefix(s)
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    x = s.interwiki_prefix(s)
  File "C:\pwb\GIT\core\pywikibot\site\_apisite.py", line 161, in interwiki_prefix
    prefixes.update(self._interwikimap.get_by_url(url))
  File "C:\pwb\GIT\core\pywikibot\site\_interwikimap.py", line 90, in get_by_url
    return {prefix for prefix, iw_entry in self._iw_sites
  File "C:\pwb\GIT\core\pywikibot\site\_interwikimap.py", line 90, in <setcomp>
    return {prefix for prefix, iw_entry in self._iw_sites
ValueError: too many values to unpack (expected 2)

Solved with patch below

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

[pywikibot/core@master] [bugfix] key, values pairs of dicts must be unpacked with items()

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

Change 677099 merged by jenkins-bot:

[pywikibot/core@master] [bugfix] key, values pairs of dicts must be unpacked with items()

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