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

why do we need to add from __future__ import absolute_import everywhere #142

Open
pavlix opened this issue Oct 3, 2016 · 3 comments
Open

Comments

@pavlix
Copy link

pavlix commented Oct 3, 2016

I'm not entirely sure why we need to add the following line to so many files where it doesn't change any behavior. Is there some good reason to do that?

from __future__ import absolute_import
@takluyver
Copy link
Contributor

I'm not sure specifically, but it should be a safe addition, and as it's easy for a user to revert or not commit any changes they don't like, I guess we err on the side of putting it in.

This fixer has a comment saying:

If there are any non-future imports, add absolute_import

@pavlix
Copy link
Author

pavlix commented Oct 28, 2016

To be honest I always commit everything changed by modernize so that the commit can be easily recreated, and I only revert in subsequent commits. On the other hand it would be nice to avoid additions that have no good reason, that's why I'm asking. I filed more important issues that haven't been answered at all, though.

@MartinFalatic
Copy link
Contributor

MartinFalatic commented Mar 22, 2018

I raised #163 originally because I couldn't exclude the import fixer precisely because it was causing issues. Despite fixing the problem I was having with actually setting that exclusion, it still happens. Now that I'm delving into the code, I see that add_future(node, 'absolute_import') is part of every call to libmodernize's touch_import() - and that gets called from almost every libmodernize fixer. While it may be safe in most instances, it can cause problems.

Why is the absolute_import future added as a side-effect of running the other fixers? I'd expect it to only happen with the import fixer (which indeed directly calls add_future(node, 'absolute_import') explicitly).

Edit: clarified that this is about this package's touch_import function, not the lib2to3 one.

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

No branches or pull requests

3 participants