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

Remove unnecessary __future__ imports #6096

Merged
merged 2 commits into from Jul 11, 2018

Conversation

Projects
None yet
3 participants
@Eric-Arellano
Copy link
Contributor

Eric-Arellano commented Jul 11, 2018

Removes from __future__ import generators, nested_scopes, with_statement from every header + updates header checker.

These future imports are enabled by default since Python 2.6 so they were redundant.

Removing them reduces duplication and simplifies code base ever so slightly.

We'll also be doing this type of change several times once we drop Python 2, e.g. removing __future__ entirely and removing from builtins imports, so this is a good first step.

FYI commands to do this

  • grep -rli 'from\ __future__\ import' src tests pants-plugins examples contrib | xargs perl -pi -e 's/.*from __future__ import.*/from __future__ import absolute_import, division, print_function, unicode_literals/'
  • grep -rli 'from\ __future__\ import' src tests pants-plugins examples contrib | xargs perl -ni -e 'print unless /.*with_statement.*/'

Impact on PRs

Pre-existing PRs either must be merged first or rebased onto this after it's merged.

Remove unnecessary __future__ imports of generators, nested_scopes, a…
…nd with_statement.

These future imports are enabled by default since Python 2.6, https://docs.python.org/2.7/reference/simple_stmts.html#future-statements, so they were redundant.

This change was generated with the following commands:
* `grep -rli 'from\ __future__\ import' src tests pants-plugins examples contrib | xargs perl -pi -e 's/.*from __future__ import.*/from __future__ import absolute_import, division, print_function, unicode_literals/'`
* `grep -rli 'from\ __future__\ import' src tests pants-plugins examples contrib | xargs perl -ni -e 'print unless /.*with_statement.*/'`
@@ -8,8 +8,8 @@
#

This comment has been minimized.

@Eric-Arellano

Eric-Arellano Jul 11, 2018

Contributor

This file has the only meaningful changes. Updates the header checker to enforce this new simplified header.

@illicitonion

This comment has been minimized.

Copy link
Contributor

illicitonion commented Jul 11, 2018

Looks good to me, thanks!

Would you like me to merge when CI goes green, or to hold off?

(A handful of tests are failing, and sadly they actually do look related to this change, but because of hard-coded values in test expectations - please can you fix them up? :))

@Eric-Arellano

This comment has been minimized.

Copy link
Contributor

Eric-Arellano commented Jul 11, 2018

@illicitonion Great! I'll fix those up.

Before you merge, I can comment on recently open green PRs and encourage them to merge, to avoid running CI again.

@stuhood
Copy link
Member

stuhood left a comment

Thanks!

@stuhood stuhood merged commit 0390517 into pantsbuild:master Jul 11, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@Eric-Arellano Eric-Arellano deleted the Eric-Arellano:simplify_future_imports branch Jul 11, 2018

Eric-Arellano added a commit that referenced this pull request Dec 14, 2018

Remove remaining unnecessary __future__ imports (#6925)
### Problem
`from __future__ import generators, nested_scopes, with_statement` are all enabled by default since Python 2.6+, so are redundant. 

#6096 removed the majority of uses, but didn't remove from `testprojects/` and `migrations/`.

### Commands to generate change
* `grep -rli 'from\ __future__\ import' testprojects migrations | xargs perl -pi -e 's/.*from __future__ import.*/from __future__ import absolute_import, division, print_function, unicode_literals/'`
* `grep -rli 'from\ __future__\ import' testprojects migrations | xargs perl -ni -e 'print unless /.*with_statement.*/'`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment