Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't apply the list constructor if it's just iterating over #140

Open
hayd opened this issue Apr 22, 2015 · 2 comments
Open

Don't apply the list constructor if it's just iterating over #140

hayd opened this issue Apr 22, 2015 · 2 comments

Comments

@hayd
Copy link

hayd commented Apr 22, 2015

At the moment futurize always adds a list constructor around python 3 iterators. Doing this creates a unnecessary copy in python 2, and an unnecessary list in python 3.

# currently
for k in d.keys():
    pass

# becomes
for k in list(d.keys()):
    pass

Because we are iterating there's no need to make this a list either in python 2 or python 3.

@lrq3000
Copy link

lrq3000 commented Aug 17, 2019

Any news on this please?

Meanwhile, is it possible to disable the adding of list() altogether using --nofix? I tried disabling a lot of fixers but could not find the one that does this, and also I want to disable THIS behavior only, not other things the fixer might do. Indeed, I have taken the habit to write keys(), values() and items() with their Py3 behavior in mind, but futurize ALWAYS adds lists, even when unnecessary (which is the case for all my calls!), thus this fixer is only making my code consume more memory and more CPU time for nothing. A simple switch to disable this specific fix altogether (ie, never add list()) would tremendously help.

@lrq3000
Copy link

lrq3000 commented Aug 17, 2019

For those having the same issue as me, it's possible to disable the annoying adding of list() everywhere by using this nofix to the futurize call: futurize --grade2 --nofix lib2to3.fixes.fix_dict *.py

But then iteritems(), iterkeys() and itervalues() won't be converted automatically, so you have to manage that manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants