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

futurize potentially changes meaning of map(...) #207

Open
AndersBlomdell opened this issue Apr 18, 2016 · 2 comments
Open

futurize potentially changes meaning of map(...) #207

AndersBlomdell opened this issue Apr 18, 2016 · 2 comments

Comments

@AndersBlomdell
Copy link

Before futurizing, the following:

#!/usr/bin/python
a='right'
print a 
v=['a', 'b', 'wrong']
m=map(lambda a: a+a, v)
print a

gives the following output:

right
right

while the futurized code:

#!/usr/bin/python
from __future__ import print_function
a='right'
print(a)
v=['a', 'b', 'wrong']
m=[a+a for a in v]
print(a)

gives the following output:

right
wrong

See http://python-history.blogspot.se/2010/06/from-list-comprehensions-to-generator.html for further explanation.

@edschofield
Copy link
Contributor

Thanks for filing this issue, Anders! Interesting ...

Would you suggest that futurize work around this problem by changing all map(f, seq) calls into list((f(item) for item in seq)) instead of [f(item) for item in seq]? This would work, but it seems a little drastic ... The other option would be a note in the docs warning about a potential change in the semantics due to Py2's leakage of list-comprehension temporary variables ...

@AndersBlomdell
Copy link
Author

I personally would go the drastic way (in fact I have started modifying all my python2 code accordingly), I do not read documentation close enough to catch this :-(, especially not if not aware of the problem beforehand.

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