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

Przemyslaw Wirkus via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 5 04:29:49 PST 2019


PrzemekWirkus added inline comments.


================
Comment at: lnt/lnttool/admin.py:8-13
+    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())
----------------
PrzemekWirkus wrote:
> thopre wrote:
> > PrzemekWirkus wrote:
> > > PrzemekWirkus wrote:
> > > > Thomas, 
> > > > why are you not using importlib.import_module instead of __import__ ?
> > > > Any other reason except for the Python 2 backward compatibility ?
> > > s/import/__import__/
> > The version available in Python 2.7 does not seem to return a value, how to bind the loaded modules to the global variables then?
> Python 2.7.15+ (default, Oct  7 2019, 17:39:04)
> [GCC 7.4.0] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import importlib
> >>> x = importlib.import_module('json')
> >>> print x
> <module 'json' from '/usr/lib/python2.7/json/__init__.pyc'>
> 
> # Silly global assign:
> >>> global json
> >>> json = x
> >>> dir(json)
> ['JSONDecoder', 'JSONEncoder', '__all__', '__author__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__', '_default_decoder', '_default_encoder', 'decoder', 'dump', 'dumps', 'encoder', 'load', 'loads', 'scanner']
> 
> https://docs.python.org/2/library/importlib.html#importlib.import_module
> 
> "...
> The specified module will be inserted into sys.modules and returned."
> 
This is just nitpicking from my side! :)


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

https://reviews.llvm.org/D68779





More information about the llvm-commits mailing list