Remove xrange for run both Python 2 and Python 3

In python 3, range() does what xrange() used to do and xrange() does not
exist. If you want to write code that will run on both Python 2 and
Python 3, you can't use xrange().

range() can actually be faster in some cases - eg. if iterating over the
same sequence multiple times. xrange() has to reconstruct the integer
object every time, but range() will have real integer objects.
(It will always perform worse in terms of memory however)

xrange() isn't usable in all cases where a real list is needed.
For instance, it doesn't support slices, or any list methods.

Change-Id: Ibe90272e96eea042f78038ec1029a5ca8e8669d8
This commit is contained in:
Luong Anh Tuan 2016-10-12 11:50:38 +07:00
parent 430d3bc762
commit e30e8effa1
1 changed files with 2 additions and 2 deletions

View File

@ -54,7 +54,7 @@ def _generate_v3_payload(log_count):
'component': 'component_%d' % it,
'service': 'service_%d' % it
}
} for it in xrange(log_count)]
} for it in range(log_count)]
v3_body = {
'dimensions': {
'origin': __name__
@ -126,7 +126,7 @@ class TestLogsMonitoring(testing.TestBase):
payload = json.dumps(v3_body)
content_length = len(payload)
side_effects = [{} for ___ in xrange(log_count - reject_logs)]
side_effects = [{} for ___ in range(log_count - reject_logs)]
side_effects.append(log_api_exceptions.HTTPUnprocessableEntity(''))
res._processor._get_dimensions = mock.Mock(side_effect=side_effects)