[issue34978] check type of object in fix_dict.py in 2to3

Pranav Devarakonda report at bugs.python.org
Sat Oct 13 20:05:49 EDT 2018


New submission from Pranav Devarakonda <devarakondapranav at yahoo.com>:

fix_dict.py applies fixes to every instance of keys(), items() or values() irrespective of the type of object. Since 2to3 cannot check the type of the object, we can at least add the check to the generated code like...

d.keys() -> list(d.keys) if type(d) == dict else d.keys()
and similarly 

d.viewkeys() -> d.keys() if type(d) == dict else d.viewkeys()

PFA the tweaked fixer.

----------
components: 2to3 (2.x to 3.x conversion tool)
files: fix_dict.py
messages: 327682
nosy: benjamin.peterson, devarakondapranav
priority: normal
severity: normal
status: open
title: check type of object in fix_dict.py in 2to3
type: enhancement
Added file: https://bugs.python.org/file47866/fix_dict.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34978>
_______________________________________


More information about the Python-bugs-list mailing list