[PATCH] D36630: [opt-viewer] Listify `dict_items` for Py3 indexing

Brian Gesiak via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 11 11:47:09 PDT 2017


modocache created this revision.

In Python 2, calling `dict.items()` returns an indexable `list`, whereas
on Python 3 it returns a set-like `dict_items` object, which cannot be
indexed. Explicitly onvert the `dict_items` object so that it can be
indexed when using Python 3.

In combination with https://reviews.llvm.org/D36622, https://reviews.llvm.org/D36623, and https://reviews.llvm.org/D36624, this change allows
`opt-viewer.py` to exit successfully when run with Python 3.4.

Test Plan:
Run `opt-viewer.py` using Python 3.4 and confirm it does not encounter a
runtime error when when indexing into `dict.items()`.


https://reviews.llvm.org/D36630

Files:
  tools/opt-viewer/optrecord.py


Index: tools/opt-viewer/optrecord.py
===================================================================
--- tools/opt-viewer/optrecord.py
+++ tools/opt-viewer/optrecord.py
@@ -146,7 +146,7 @@
             del mapping['DebugLoc']
 
         assert(len(mapping) == 1)
-        (key, value) = mapping.items()[0]
+        (key, value) = list(mapping.items())[0]
 
         if key == 'Caller' or key == 'Callee':
             value = cgi.escape(demangle(value))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36630.110782.patch
Type: text/x-patch
Size: 458 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170811/02a20f99/attachment.bin>


More information about the llvm-commits mailing list