[PATCH] D68779: [LNT] Fix global import in function

Thomas Preud'homme via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 10 04:05:16 PDT 2019


thopre created this revision.
thopre added reviewers: cmatthews, hubert.reinterpretcast, kristof.beyls.

The _load_dependencies() function in lnt.lnttool.admin import some
modules in the global namespace by making the module name global and
then doing imports. However the language reference for global statements
forbids this:

"Names listed in a global statement must not be defined as formal
parameters or in a for loop control target, class definition, function
definition, or import statement."

This commit makes use of __import__ builtin instead of the import
statement to respect this restriction.


https://reviews.llvm.org/D68779

Files:
  lnt/lnttool/admin.py


Index: lnt/lnttool/admin.py
===================================================================
--- lnt/lnttool/admin.py
+++ lnt/lnttool/admin.py
@@ -5,12 +5,12 @@
 
 def _load_dependencies():
     global yaml, sys, requests, json, os, httplib
-    import yaml
-    import sys
-    import requests
-    import json
-    import os
-    import httplib
+    yaml = __import__('yaml', globals(), locals())
+    sys = __import__('sys', globals(), locals())
+    requests = __import__('requests', globals(), locals())
+    json = __import__('json', globals(), locals())
+    os = __import__('os', globals(), locals())
+    httplib = __import__('httplib', globals(), locals())
 
 
 def _error(msg):


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68779.224304.patch
Type: text/x-patch
Size: 692 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191010/56b40951/attachment.bin>


More information about the llvm-commits mailing list