Skip to content

Commit 82bfa4f

Browse files
author
Thomas Preud'homme
committed
[LNT] Python 3 support: use Python 3 idioms
Replace Python 2 idioms for their Python 3 counterparts. These includes: - replace calls to X.sort() optionally followed by .reverse() by calls to sorted(X) - replace while 1 by while True This was produced by running futurize's stage1 lib2to3.fixes.fix_idioms. Reviewers: cmatthews, hubert.reinterpretcast, kristof.beyls Reviewed By: hubert.reinterpretcast Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D67809 llvm-svn: 372476
1 parent 35bb501 commit 82bfa4f

File tree

7 files changed

+26
-47
lines changed

7 files changed

+26
-47
lines changed

lnt/external/stats/pstat.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,7 @@ def collmean (inlist):
281281
return means
282282
else:
283283
values = colex(listoflists,keepcols)
284-
uniques = unique(values)
285-
uniques.sort()
284+
uniques = sorted(unique(values))
286285
newlist = []
287286
if not isinstance(keepcols, (list, tuple)): keepcols = [keepcols]
288287
for item in uniques:
@@ -646,8 +645,7 @@ def sortby(listoflists,sortcols):
646645
Usage: sortby(listoflists,sortcols)
647646
Returns: sorted list, unchanged column ordering
648647
"""
649-
newlist = abut(colex(listoflists,sortcols),listoflists)
650-
newlist.sort()
648+
newlist = sorted(abut(colex(listoflists, sortcols), listoflists))
651649
try:
652650
numcols = len(sortcols)
653651
except TypeError:
@@ -807,8 +805,7 @@ def acollmean (inarray):
807805
if not isinstance(keepcols, (list, tuple, N.ndarray)):
808806
keepcols = [keepcols]
809807
values = colex(a,keepcols) # so that "item" can be appended (below)
810-
uniques = unique(values) # get a LIST, so .sort keeps rows intact
811-
uniques.sort()
808+
uniques = sorted(unique(values)) # get a LIST, so .sort keeps rows intact
812809
newlist = []
813810
for item in uniques:
814811
if not isinstance(item, (list, tuple, N.ndarray)):

lnt/external/stats/stats.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,7 @@ def lmedianscore (inlist):
337337
Usage: lmedianscore(inlist)
338338
"""
339339

340-
newlist = copy.deepcopy(inlist)
341-
newlist.sort()
340+
newlist = sorted(copy.deepcopy(inlist))
342341
if len(newlist) % 2 == 0: # if even number of scores, average middle 2
343342
index = len(newlist)/2 # integer division correct
344343
median = float(newlist[index] + newlist[index-1]) /2
@@ -358,8 +357,7 @@ def lmode(inlist):
358357
Returns: bin-count for mode(s), a list of modal value(s)
359358
"""
360359

361-
scores = pstat.unique(inlist)
362-
scores.sort()
360+
scores = sorted(pstat.unique(inlist))
363361
freq = []
364362
for item in scores:
365363
freq.append(inlist.count(item))
@@ -458,8 +456,7 @@ def litemfreq(inlist):
458456
Usage: litemfreq(inlist)
459457
Returns: a 2D frequency table (col [0:n-1]=scores, col n=frequencies)
460458
"""
461-
scores = pstat.unique(inlist)
462-
scores.sort()
459+
scores = sorted(pstat.unique(inlist))
463460
freq = []
464461
for item in scores:
465462
freq.append(inlist.count(item))
@@ -2028,9 +2025,7 @@ def ageometricmean (inarray,dimension=None,keepdims=0):
20282025
shp[dimension] = 1
20292026
sum = N.reshape(sum,shp)
20302027
else: # must be a SEQUENCE of dims to average over
2031-
dims = list(dimension)
2032-
dims.sort()
2033-
dims.reverse()
2028+
dims = sorted(dimension, reverse=True)
20342029
size = N.array(N.multiply.reduce(N.take(inarray.shape,dims)),N.float_)
20352030
mult = N.power(inarray,1.0/size)
20362031
for dim in dims:
@@ -2069,8 +2064,7 @@ def aharmonicmean (inarray,dimension=None,keepdims=0):
20692064
shp[dimension] = 1
20702065
s = N.reshape(s,shp)
20712066
else: # must be a SEQUENCE of dims to average over
2072-
dims = list(dimension)
2073-
dims.sort()
2067+
dims = sorted(dimension)
20742068
nondims = []
20752069
for i in range(len(inarray.shape)):
20762070
if i not in dims:
@@ -2124,9 +2118,7 @@ def amean (inarray,dimension=None,keepdims=0):
21242118
shp[dimension] = 1
21252119
sum = N.reshape(sum,shp)
21262120
else: # must be a TUPLE of dims to average over
2127-
dims = list(dimension)
2128-
dims.sort()
2129-
dims.reverse()
2121+
dims = sorted(dimension, reverse=True)
21302122
sum = inarray *1.0
21312123
for dim in dims:
21322124
sum = N.add.reduce(sum,dim)
@@ -4165,9 +4157,7 @@ def asum (a, dimension=None,keepdims=0):
41654157
shp[dimension] = 1
41664158
s = N.reshape(s,shp)
41674159
else: # must be a SEQUENCE of dims to sum over
4168-
dims = list(dimension)
4169-
dims.sort()
4170-
dims.reverse()
4160+
dims = sorted(dimension, reverse=True)
41714161
s = a *1.0
41724162
for dim in dims:
41734163
s = N.add.reduce(s,dim)
@@ -4192,9 +4182,7 @@ def acumsum (a,dimension=None):
41924182
a = N.ravel(a)
41934183
dimension = 0
41944184
if isinstance(dimension, (list, tuple, N.ndarray)):
4195-
dimension = list(dimension)
4196-
dimension.sort()
4197-
dimension.reverse()
4185+
dimension = sorted(dimension, reverse=True)
41984186
for d in dimension:
41994187
a = N.add.accumulate(a,d)
42004188
return a

lnt/server/db/testsuitedb.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -904,11 +904,8 @@ def _getOrCreateOrder(self, session, run_parameters):
904904
session.add(order)
905905
session.commit()
906906

907-
# Load all the orders.
908-
orders = list(session.query(self.Order))
909-
910-
# Sort the objects to form the total ordering.
911-
orders.sort()
907+
# Load all the orders and sort them to form the total ordering.
908+
orders = sorted(session.query(self.Order))
912909

913910
# Find the order we just added.
914911
index = orders.index(order)
@@ -1128,10 +1125,13 @@ def get_adjacent_runs_on_machine(self, session, run, N, direction=-1):
11281125
#
11291126
# FIXME: Scalability! However, pretty fast in practice, see elaborate
11301127
# explanation above.
1131-
all_machine_orders = session.query(self.Order).\
1132-
join(self.Run).\
1133-
filter(self.Run.machine == run.machine).distinct().all()
1134-
all_machine_orders.sort()
1128+
all_machine_orders = sorted(
1129+
session.query(self.Order)
1130+
.join(self.Run)
1131+
.filter(self.Run.machine == run.machine)
1132+
.distinct()
1133+
.all()
1134+
)
11351135

11361136
# Find the index of the current run.
11371137
index = all_machine_orders.index(run.order)

lnt/server/ui/util.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ def mean(values):
7474

7575

7676
def median(values):
77-
values = list(values)
78-
values.sort()
77+
values = sorted(values)
7978
N = len(values)
8079
return (values[(N - 1) // 2] +
8180
values[(N + 0) // 2]) * .5

lnt/server/ui/views.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,7 @@ def v4_machine(id):
305305
.join(ts.Order)
306306
.filter(ts.Run.machine_id == id)
307307
.order_by(ts.Run.start_time.desc())))
308-
associated_runs = associated_runs.items()
309-
associated_runs.sort()
308+
associated_runs = sorted(associated_runs.items())
310309

311310
try:
312311
machine = session.query(ts.Machine).filter(ts.Machine.id == id).one()
@@ -658,11 +657,8 @@ def v4_all_orders():
658657
session = request.session
659658
ts = request.get_testsuite()
660659

661-
# Get the orders.
662-
orders = session.query(ts.Order).all()
663-
664-
# Order the runs totally.
665-
orders.sort()
660+
# Get the orders and sort them totally.
661+
orders = sorted(session.query(ts.Order).all())
666662

667663
return render_template("v4_all_orders.html", orders=orders, **ts_data(ts))
668664

lnt/util/stats.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ def agg_mean(pairs):
5454
def median(values):
5555
if not values:
5656
return None
57-
values = list(values)
58-
values.sort()
57+
values = sorted(values)
5958
N = len(values)
6059
return (values[(N - 1) // 2] + values[N // 2]) * .5
6160

lnt/util/wsgi_restart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _modified(path):
5858

5959

6060
def _monitor():
61-
while 1:
61+
while True:
6262
# Check modification times on all files in sys.modules.
6363

6464
for module in sys.modules.values():

0 commit comments

Comments
 (0)