This is an archive of the discontinued LLVM Phabricator instance.

[LNT] Python 3 support: Minor automatic 2to3 fixups
ClosedPublic

Authored by hubert.reinterpretcast on Sep 12 2019, 9:15 PM.

Details

Summary

Automatic fixups done using 2to3:

  • 2to3 -f numliterals
  • 2to3 -f dict
  • 2to3 -f map
  • 2to3 -f exec

The exec call is additionally updated to have a string argument as noted by @thopre.
The changes cover the files found to be affected when running tests (without result submission).

Diff Detail

Repository
rL LLVM

Event Timeline

I got a lot more changes with futurize. In particular it adds:

+from builtins import map
+from builtins import zip

everywhere where map or zip is used, to ensure python3 behavior with python2.

lnt/lnttool/create.py
162 ↗(On Diff #220040)

I initially thought of using

os.chmod(wsgi_path, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)

instead. Maybe 0o755 is indeed more readable.

lnt/server/instance.py
57 ↗(On Diff #220040)

exec in Python3 does not read from a file descriptor according to the doc. You'd need exec(open(config_path).read(), config_data) AFAIK.

See [1] (which contains "If it is an open file, the file is parsed until EOF and executed") Vs [2] (which contains "object must be either a string or a code object").

[1] https://docs.python.org/2/reference/simple_stmts.html#grammar-token-exec-stmt
[2] https://docs.python.org/3/library/functions.html#exec

hubert.reinterpretcast marked 2 inline comments as done.Sep 13 2019, 5:20 AM

I got a lot more changes with futurize. In particular it adds:

+from builtins import map
+from builtins import zip

everywhere where map or zip is used, to ensure python3 behavior with python2.

I'm not sure it is worth requiring an additional package (future).

lnt/lnttool/create.py
162 ↗(On Diff #220040)

I think 0o755 is more readable.

lnt/server/instance.py
57 ↗(On Diff #220040)

Confirmed:

TypeError: exec() arg 1 must be a string, bytes or code object

Will change.

I got a lot more changes with futurize. In particular it adds:

+from builtins import map
+from builtins import zip

everywhere where map or zip is used, to ensure python3 behavior with python2.

I'm not sure it is worth requiring an additional package (future).

Ah apparently it's only to ensure the new code is not too slow on python2: https://python-future.org/compatible_idioms.html#map

So I agree, this can be skipped, especially given how soon will python2 be EOL.

hubert.reinterpretcast marked an inline comment as done.
  • Update exec call to have a string argument
This revision is now accepted and ready to land.Sep 13 2019, 10:46 AM
hubert.reinterpretcast edited the summary of this revision. (Show Details)Sep 13 2019, 1:45 PM
hubert.reinterpretcast marked 2 inline comments as done.
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 13 2019, 1:51 PM