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

Hubert Tong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 13 05:21:13 PDT 2019


hubert.reinterpretcast marked 2 inline comments as done.
hubert.reinterpretcast added a comment.

In D67534#1669092 <https://reviews.llvm.org/D67534#1669092>, @thopre wrote:

> 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`).



================
Comment at: lnt/lnttool/create.py:162
     wsgi_file.close()
-    os.chmod(wsgi_path, 0755)
+    os.chmod(wsgi_path, 0o755)
 
----------------
thopre wrote:
> 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.
I think `0o755` is more readable.


================
Comment at: lnt/server/instance.py:57
         config_data = {}
-        exec open(config_path) in config_data
+        exec(open(config_path), config_data)
         config = lnt.server.config.Config.from_data(config_path, config_data)
----------------
thopre wrote:
> 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
Confirmed:
```
TypeError: exec() arg 1 must be a string, bytes or code object
```

Will change.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67534/new/

https://reviews.llvm.org/D67534





More information about the llvm-commits mailing list