Skip to content

Commit 0cf7cfc

Browse files
author
Thomas Preud'homme
committed
[LNT] Python 3 support: adapt to dict method returning views
Adapt calls to dictionary's keys(), items() and values() to them returning a view in Python 3 when necessary, undoing unneeded changes in lnt/testing/__init__.py. Also replace calls to their iter relatives to use iter() instead and calls to the their views relatives to use the plains .keys(), .items() and .values(). This was produced by running futurize's stage2 lib2to3.fixes.fix_dict with manual intervention to clean up code and remove unnecessary list() wrapping. Reviewers: cmatthews, hubert.reinterpretcast, kristof.beyls Reviewed By: hubert.reinterpretcast Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D67814 llvm-svn: 372816
1 parent e455056 commit 0cf7cfc

File tree

10 files changed

+18
-17
lines changed

10 files changed

+18
-17
lines changed

examples/run_to_csv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
data = json.load(sys.stdin)
99

10-
titles = data['tests'].itervalues().next().keys()
10+
titles = list(next(iter(data['tests'].values())).keys())
1111
titles.insert(0, titles.pop(titles.index("name")))
1212

1313
print(", ".join(titles))

lnt/server/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,4 @@ def get_database(self, name):
191191
db_entry.baseline_revision)
192192

193193
def get_database_names(self):
194-
return self.databases.keys()
194+
return list(self.databases.keys())

lnt/server/reporting/summaryreport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def get_datapoints_for_sample(ts, sample):
342342
columns = [ts.Sample.run_id, ts.Sample.test_id]
343343
columns.extend(f.column for f in ts.sample_fields)
344344
samples = session.query(*columns).filter(
345-
ts.Sample.run_id.in_(run_id_map.keys()))
345+
ts.Sample.run_id.in_(list(run_id_map.keys())))
346346
for sample in samples:
347347
run = run_id_map[sample[0]]
348348
datapoints = list()

lnt/server/ui/regression_views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ class EditRegressionForm(Form):
256256
title = StringField(u'Title', validators=[DataRequired()])
257257
bug = StringField(u'Bug', validators=[DataRequired()])
258258
field_changes = MultiCheckboxField("Changes", coerce=int)
259-
choices = RegressionState.names.items()
259+
choices = list(RegressionState.names.items())
260260
state = SelectField(u'State', choices=choices)
261261
edit_state = HiddenField(u'EditState', validators=[DataRequired()])
262262

lnt/server/ui/views.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,9 @@ def v4_graph():
951951
(field.status_field.column.is_(None)))
952952

953953
# Aggregate by revision.
954-
data = multidict.multidict((rev, (val, date, run_id))
955-
for val, rev, date, run_id in q).items()
954+
data = list(multidict.multidict((rev, (val, date, run_id))
955+
for val, rev, date, run_id in q)
956+
.items())
956957

957958
data.sort(key=lambda sample: convert_revision(sample[0], cache=revision_cache))
958959

lnt/testing/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def __init__(self, name, samples, info={}, report_version=2):
257257
self.samples = samples
258258
self.info = dict()
259259
# Convert keys/values that are not json encodable to strings.
260-
for key, value in list(info.items()):
260+
for key, value in info.items():
261261
key = str(key)
262262
value = str(value)
263263
self.info[key] = value

lnt/testing/profile/profilev2impl.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,9 @@ def deserialize(self, fobj):
266266
def upgrade(self, impl):
267267
self.idx_to_name = {}
268268

269-
keys = impl.getTopLevelCounters().keys()
269+
keys = list(impl.getTopLevelCounters().keys())
270270
for f in impl.getFunctions().values():
271-
keys += f['counters'].keys()
271+
keys.extend(f['counters'].keys())
272272
keys = sorted(set(keys))
273273

274274
self.idx_to_name = {k: v for k, v in enumerate(keys)}
@@ -313,9 +313,9 @@ def serialize(self, fobj):
313313
start = fobj.tell()
314314
for fname, f in sorted(self.impl.getFunctions().items()):
315315
self.function_offsets[fname] = fobj.tell() - start
316-
all_counters = f['counters'].keys()
316+
all_counters = sorted(f['counters'].keys())
317317
for counters, address, text in self.impl.getCodeForFunction(fname):
318-
for k in sorted(all_counters):
318+
for k in all_counters:
319319
writeFloat(fobj, counters.get(k, 0))
320320

321321
def deserialize(self, fobj):
@@ -537,7 +537,7 @@ def upgrade(self, impl):
537537
def getCodeForFunction(self, fname):
538538
f = self.functions[fname]
539539
counter_gen = self.line_counters \
540-
.extractForFunction(fname, f['counters'].keys())
540+
.extractForFunction(fname, list(f['counters'].keys()))
541541
address_gen = self.line_addresses.extractForFunction(fname)
542542
text_gen = self.line_text.extractForFunction(fname)
543543
for n in xrange(f['length']):

lnt/tests/nt.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,14 +1479,14 @@ def _process_reruns(config, server_reply, local_results):
14791479
for test in collated_results.values():
14801480
test.check()
14811481

1482-
rerunable_benches = [x for x in collated_results.values()
1483-
if x.is_rerunable()]
1482+
rerunable_benches = list(filter(lambda bench: bench.is_rerunable(),
1483+
collated_results.values()))
14841484
rerunable_benches.sort(key=lambda x: x.name)
14851485
# Now lets do the reruns.
14861486
rerun_results = []
14871487
summary = "Rerunning {} of {} benchmarks."
14881488
logger.info(summary.format(len(rerunable_benches),
1489-
len(collated_results.values())))
1489+
len(collated_results)))
14901490

14911491
for i, bench in enumerate(rerunable_benches):
14921492
logger.info("Rerunning: {} [{}/{}]".format(bench.name,

tests/server/ui/V4Pages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def get_xml_tree(html_string):
111111
try:
112112
parser = ET.XMLParser()
113113
parser.parser.UseForeignDTD(True)
114-
parser.entity.update((x, unichr(i)) for x, i in name2codepoint.iteritems())
114+
parser.entity.update((x, unichr(i)) for x, i in name2codepoint.items())
115115
tree = ET.fromstring(html_string, parser=parser)
116116
except: # noqa FIXME: figure out what we expect this to throw.
117117
dump_html(html_string)

tests/server/ui/test_roundtrip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def _compare_results(self, after_submit_run, before_submit_run):
8989
before_submit_run['run']['order_id'] = an_id
9090
after_submit_run['run']['order_id'] = an_id
9191

92-
self.assertEqual(before_submit_run.keys(), after_submit_run.keys())
92+
self.assertEqual(list(before_submit_run.keys()), list(after_submit_run.keys()))
9393
# Machine and run will be dicts, compare them directly.
9494
for k in ['machine', 'run']:
9595
self.assertEqual(before_submit_run[k], after_submit_run[k])

0 commit comments

Comments
 (0)