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.
Running
python-modernize
on code using bothmap
anditertools.imap
produces the wrong code. For example, runningpython-modernize
on the following codeproduces non-working code.
python-modernize
doesn't changemap(add_1, [1, 2, 3])
tolist(map(add_1, [1, 2, 3]))
as it should. The issue seems to be caused bylibmodernize.fixes.fix_itertools_imports_six
fixer running beforelibmodernize.fixes.fix_map
by default. Changing the run order ofFixItertoolsImportsSix
class to 6 modifies the code correctly.