Skip to content

Commit a5e7fc6

Browse files
author
Thomas Preud'homme
committed
[LNT] Python 3 support: replace xrange with Python3's range
Summary: Use Python 3's range instead of xrange by importing it from builtins. Also encapsulate existing uses of range into a call to list since it returns an immutable sequence type in Python 3. This was produced by running futurize's stage2 libfuturize.fixes.fix_xrange_with_import. Reviewers: cmatthews, hubert.reinterpretcast, kristof.beyls, leandron, PrzemekWirkus Reviewed By: PrzemekWirkus Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D67881
1 parent 156c369 commit a5e7fc6

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

lnt/external/stats/stats.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ def lpointbiserialr(x, y):
911911
if len(categories) != 2:
912912
raise ValueError("Exactly 2 categories required for pointbiserialr().")
913913
else: # there are 2 categories, continue
914-
codemap = pstat.abut(categories, range(2))
914+
codemap = pstat.abut(categories, list(range(2)))
915915
recoded = pstat.recode(data, codemap, 0)
916916
x = pstat.linexand(data, 0, categories[0])
917917
y = pstat.linexand(data, 0, categories[1])
@@ -1746,7 +1746,7 @@ def lshellsort(inlist):
17461746
"""
17471747
n = len(inlist)
17481748
svec = copy.deepcopy(inlist)
1749-
ivec = range(n)
1749+
ivec = list(range(n))
17501750
gap = n // 2 # integer division needed
17511751
while gap >0:
17521752
for i in range(gap, n):
@@ -4259,7 +4259,7 @@ def ashellsort(inarray):
42594259
"""
42604260
n = len(inarray)
42614261
svec = inarray *1.0
4262-
ivec = range(n)
4262+
ivec = list(range(n))
42634263
gap = n // 2 # integer division needed
42644264
while gap >0:
42654265
for i in range(gap, n):

lnt/testing/profile/profilev2impl.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from __future__ import absolute_import
2+
from builtins import range
23
from .profile import ProfileImpl
34
import StringIO
45
import bz2
@@ -252,12 +253,12 @@ class CounterNamePool(Section):
252253
def serialize(self, fobj):
253254
n_names = len(self.idx_to_name)
254255
writeNum(fobj, n_names)
255-
for i in xrange(n_names):
256+
for i in range(n_names):
256257
writeString(fobj, self.idx_to_name[i])
257258

258259
def deserialize(self, fobj):
259260
self.idx_to_name = {}
260-
for i in xrange(readNum(fobj)):
261+
for i in range(readNum(fobj)):
261262
self.idx_to_name[i] = readString(fobj)
262263
self.name_to_idx = {v: k
263264
for k, v
@@ -287,7 +288,7 @@ def serialize(self, fobj):
287288

288289
def deserialize(self, fobj):
289290
self.counters = {}
290-
for i in xrange(readNum(fobj)):
291+
for i in range(readNum(fobj)):
291292
k = readNum(fobj)
292293
v = readNum(fobj)
293294
self.counters[self.counter_name_pool.idx_to_name[k]] = v
@@ -514,7 +515,7 @@ def serialize(self, fobj):
514515

515516
def deserialize(self, fobj):
516517
self.functions = {}
517-
for i in xrange(readNum(fobj)):
518+
for i in range(readNum(fobj)):
518519
f = {}
519520
name = readString(fobj)
520521
f['length'] = readNum(fobj)
@@ -523,7 +524,7 @@ def deserialize(self, fobj):
523524
self.line_text.setOffsetFor(name, readNum(fobj))
524525
f['counters'] = {}
525526

526-
for j in xrange(readNum(fobj)):
527+
for j in range(readNum(fobj)):
527528
k = self.counter_name_pool.idx_to_name[readNum(fobj)]
528529
v = readFloat(fobj)
529530
f['counters'][k] = v
@@ -540,7 +541,7 @@ def getCodeForFunction(self, fname):
540541
.extractForFunction(fname, list(f['counters'].keys()))
541542
address_gen = self.line_addresses.extractForFunction(fname)
542543
text_gen = self.line_text.extractForFunction(fname)
543-
for n in xrange(f['length']):
544+
for n in range(f['length']):
544545
yield (next(counter_gen), next(address_gen), next(text_gen))
545546

546547
def copy(self, counter_name_pool, line_counters,

lnt/tests/nt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ def rerun_test(config, name, num_times):
12111211

12121212
results = []
12131213
no_errors = True
1214-
for _ in xrange(0, num_times):
1214+
for _ in range(0, num_times):
12151215
test_results, t_no_errors = _execute_test_again(
12161216
config, test_name, test_full_path, relative_test_path, logfile)
12171217
no_errors &= t_no_errors

tests/utils/blast.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
## Just to make sure there are no syntax errors in this. This does not
99
## actually run a blast.
1010
# RUN: python %{src_root}/tests/utils/blast.py
11+
from builtins import range
1112
import time
1213
import subprocess
1314
import os
@@ -45,7 +46,7 @@ def rand_sample():
4546
"""Make a random sized list of random samples."""
4647
r = random.randint(1, 20)
4748
samples = []
48-
for i in xrange(r):
49+
for i in range(r):
4950
samples.append(random.random() * 100)
5051
return samples
5152

@@ -65,7 +66,7 @@ def rand_sample():
6566
print("Usage: python blast.py <num_submissions> <sleep_between> [optional url]")
6667
sys.exit(0)
6768

68-
for i in xrange(int(sys.argv[1])):
69+
for i in range(int(sys.argv[1])):
6970
machine = lnt.testing.Machine(MACH, DEFAULT_MACHINE_INFO)
7071
run = lnt.testing.Run(start_time, end_time, run_info)
7172
report = lnt.testing.Report(machine=machine, run=run, tests=[])

0 commit comments

Comments
 (0)