Page MenuHomePhabricator

"TypeError: 'dict_keys' object does not support indexing" in cosmetic_changes.py (Python 3)
Closed, ResolvedPublic

Description

Traceback (most recent call last):
  File "xyz\xxx\yyy.py", line 89, in <module>
    page.put(page_text, summary)
  File "xyz\pywikibot-core\pywikibot\tools\__init__.py", line 1105, in wrapper
    return obj(*__args, **__kw)
  File "xyz\pywikibot-core\pywikibot\page.py", line 1144, in put
    **kwargs)
  File "xyz\pywikibot-core\pywikibot\tools\__init__.py", line 1105, in wrapper
    return obj(*__args, **__kw)
  File "xyz\pywikibot-core\pywikibot\page.py", line 1062, in save
    cc=apply_cosmetic_changes, **kwargs)
  File "xyz\pywikibot-core\pywikibot\page.py", line 1070, in _save
    summary = self._cosmetic_changes_hook(summary) or summary
  File "xyz\pywikibot-core\pywikibot\page.py", line 1120, in _cosmetic_changes_hook
    self.text = ccToolkit.change(old)
  File "xyz\pywikibot-core\pywikibot\cosmetic_changes.py", line 279, in change
    new_text = self._change(text)
  File "xyz\pywikibot-core\pywikibot\cosmetic_changes.py", line 273, in _change
    text = self.safe_execute(method, text)
  File "xyz\pywikibot-core\pywikibot\cosmetic_changes.py", line 260, in safe_execute
    result = method(text)
  File "xyz\pywikibot-core\pywikibot\cosmetic_changes.py", line 849, in fixArabicLetters
    old = digits[digits.keys()[0]]
TypeError: 'dict_keys' object does not support indexing

In Python 3 the dict.keys() method returns a dictionary view object, which does not support indexing.

Event Timeline

Dalba raised the priority of this task from to Needs Triage.
Dalba updated the task description. (Show Details)
Dalba added a project: Pywikibot.
Dalba subscribed.
Restricted Application added subscribers: Aklapper, Unknown Object (MLST). · View Herald TranscriptJun 9 2015, 2:30 AM
jayvdb triaged this task as High priority.Jun 9 2015, 5:28 AM
Dalba set Security to None.

digits[digits.keys()[0]] might become list(digits.values())[0], but that part looks broken anyway...

It seems that this code isn't actually used further down.

The second half of this method was de-activated due to T57185.

Change 246793 had a related patch set uploaded (by John Vandenberg):
Fix Python 3 TypeError in fixArabicLetters

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

Change 246793 abandoned by Xqt:
Add CC -experimental to use disabled fixes

Reason:
-experimental does not solve that issue

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