PyCQA / modernize

Modernizes Python code for eventual Python 3 migration. Built on top of fissix (a fork of lib2to3)
https://modernize.readthedocs.org/
Other
355 stars 51 forks source link

Incorrect changes on code using both map and itertools.imap #175

Open jbradaric opened 5 years ago

jbradaric commented 5 years ago

Running python-modernize on code using both map and itertools.imap produces the wrong code. For example, running python-modernize on the following code

from itertools import imap

def add_1(x):
    return x + 1

assert isinstance(map(add_1, [1, 2, 3]), list)
assert not isinstance(imap(add_1, [1, 2, 3]), list)

produces non-working code. python-modernize doesn't change map(add_1, [1, 2, 3]) to list(map(add_1, [1, 2, 3])) as it should. The issue seems to be caused by libmodernize.fixes.fix_itertools_imports_six fixer running before libmodernize.fixes.fix_map by default. Changing the run order of FixItertoolsImportsSix class to 6 modifies the code correctly.