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

Thomas Preud'homme via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 5 04:51:07 PST 2019


thopre marked 5 inline comments as done.
thopre 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:
> 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! :)
Ah, I missed the "and returned". Thanks for pointing that out. It seems that importlib is only available in Python 3.1 onwards. Are you aware of any Linux distribution (past or present, e.g. RHELs) that ship with Python 3.0?


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

https://reviews.llvm.org/D68779





More information about the llvm-commits mailing list