Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Convert six.moves.xrange() to range() for Python 3 #10525

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

Merged
merged 1 commit into from
Feb 21, 2018

Conversation

cclauss
Copy link

@cclauss cclauss commented Feb 18, 2018

PR Summary

As part of dropping support for Python 2, we can simplify the code by:

  • removing all instances from six.moves import xrange and
  • converting all calls to xrange() into calls to range().

Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

Thanks this seems fine. I assume you did a grep for all instances of xrange...

@efiring
Copy link
Member

efiring commented Feb 19, 2018

See #10526 for the solution to the problem with _axes.py.

@@ -941,7 +941,7 @@ def get_split_ind(seq, N):

s_len = 0
# todo: use Alex's xrange pattern from the cbook for efficiency
for (word, ind) in zip(seq, xrange(len(seq))):
for (word, ind) in zip(seq, range(len(seq))):
Copy link
Contributor

Choose a reason for hiding this comment

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

these functions should just be deleted as they have been deprecated since 2.1

@@ -1098,7 +1098,7 @@ def allequal(seq):
if len(seq) < 2:
return True
val = seq[0]
for i in xrange(1, len(seq)):
for i in range(1, len(seq)):
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

@@ -561,9 +561,9 @@ def add_lines(self, levels, colors, linewidths, erase=True):
x = np.array([0.0, 1.0])
X, Y = np.meshgrid(x, y)
if self.orientation == 'vertical':
xy = [list(zip(X[i], Y[i])) for i in xrange(N)]
xy = [list(zip(X[i], Y[i])) for i in range(N)]
Copy link
Contributor

Choose a reason for hiding this comment

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

probably better written using np.stack or a variant of it

@@ -2641,7 +2641,7 @@ def symbol(self, s, loc, toks):
if c in self._spaced_symbols:
# iterate until we find previous character, needed for cases
# such as ${ -2}$, $ -2$, or $ -2$.
for i in six.moves.xrange(1, loc + 1):
for i in range(1, loc + 1):
Copy link
Contributor

Choose a reason for hiding this comment

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

already refactored in the py3mathtext PR

@@ -597,7 +596,7 @@ def render_figures(code, code_path, output_dir, output_base, context,
all_exists = True
for i, code_piece in enumerate(code_pieces):
images = []
for j in xrange(1000):
for j in range(1000):
Copy link
Contributor

Choose a reason for hiding this comment

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

probably should be itertools.count()...

@@ -529,9 +529,9 @@ def _edges(self, X, Y):
# Using the non-array form of these line segments is much
# simpler than making them into arrays.
if self.orientation == 'vertical':
return [list(zip(X[i], Y[i])) for i in xrange(1, N-1)]
return [list(zip(X[i], Y[i])) for i in range(1, N-1)]
Copy link
Contributor

Choose a reason for hiding this comment

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

see above re np.stack

@tacaswell tacaswell added this to the v3.0 milestone Feb 19, 2018
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.

6 participants