This is an archive of the discontinued LLVM Phabricator instance.

Make utils/UpdateTestChecks/common.py Python 2/3 compatible and fix print statements.
ClosedPublic

Authored by MaskRay on Jan 29 2018, 6:18 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

MaskRay created this revision.Jan 29 2018, 6:18 PM
MaskRay edited the summary of this revision. (Show Details)Jan 31 2018, 9:51 AM
MaskRay added reviewers: craig.topper, asb, echristo.
asb added a subscriber: modocache.

Adding @modocache as reviewer, who has been responsible for making the opt-viewer tools Py2+Py3 compatible. The changes look sensible to me, but the vast majority of the Python I've written for a long time has been Py3.

sys is missing so without the revision, --verbose will complain the name is undefined

Mostly looks good, but I had one suggestion!

utils/UpdateTestChecks/common.py
41 ↗(On Diff #131910)

I think you can call decode regardless. For example, the following code works on both Python 2 and 3:

from __future__ import print_function
import subprocess

out = subprocess.check_output(['ls']).decode()
print(out)

Here it is in an online Python 2 and Python 3 interpreter. (I don't think there's much overhead to doing so on Python 2, but if you're worried about that it might be worth looking into.)

Mostly looks good, but I had one suggestion!

In Python 2, str.decode returns unicode. I just want to ensure everything is str in both Python 2 and Python 3.

Oh I see! Thanks for the tip, I didn't know that.

modocache accepted this revision.Feb 1 2018, 5:41 PM

Oops, sorry, I should have accepted this revision along with my last comment. Thanks for making this change!

This revision is now accepted and ready to land.Feb 1 2018, 5:41 PM
This revision was automatically updated to reflect the committed changes.