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

[BEAM-1251] Migrate away from xrange() #4570

Merged
merged 1 commit into from
Feb 14, 2018

Conversation

cclauss
Copy link

@cclauss cclauss commented Feb 1, 2018

xrange() was removed from Python 3 in favor of an iterator-based range().

For all files that use the Python 2-only builtin function xrange(), add the line from six.moves import xrange for compatibility with both Python 2 and Python 3.

@robertwb
Copy link
Contributor

robertwb commented Feb 1, 2018

It seems for most, if not all, of these uses of xrange, range would be perfectly acceptable as well (i.e. the ranges in question are quite small). Could you change these to use the vanilla range rather than import xrange from six?

@cclauss
Copy link
Author

cclauss commented Feb 1, 2018

The lifetime of Python 2 is now just two years long. An alternative (probably safer) approach would be to leave this PRs as written until 2020 and then dropping Python 2 support will only require 1) removing the import and 2) doing a global find-and-replace of 'xrange(' --> 'range('.

I am willing to go whichever way you feel is best.

@robertwb
Copy link
Contributor

robertwb commented Feb 1, 2018

Unless there is a compelling reason to use xrange over range for any of these in Python 2 (I don't see one), let's change to range now.

@cclauss cclauss force-pushed the from-six.moves-import-xrange branch from 241be26 to 774fb62 Compare February 1, 2018 22:02
@cclauss
Copy link
Author

cclauss commented Feb 1, 2018

I could not see any of these that I felt needed to be iterators in Python 2. Please let me know is you see any that could get massive.

@robertwb
Copy link
Contributor

robertwb commented Feb 1, 2018

All look good to me. Will merge once all tests pass (not that I'm worried).

@@ -21,7 +21,6 @@
import os.path
import pickle
import unittest

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint seems to want this newline.

@cclauss cclauss force-pushed the from-six.moves-import-xrange branch from e6eb12d to c635c63 Compare February 1, 2018 22:52
@cclauss
Copy link
Author

cclauss commented Feb 6, 2018

@robertwb Is there something more that I need to do on this PR?

@robertwb robertwb changed the title xrange() was removed in Python 3 (en masse) [BEAM-1251] Migrate away from xrange() Feb 14, 2018
@robertwb robertwb merged commit 08f3ffa into apache:master Feb 14, 2018
@cclauss cclauss deleted the from-six.moves-import-xrange branch February 14, 2018 00:02
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

Successfully merging this pull request may close these issues.

2 participants