Brett Cannon added the comment:

If I were to change this code in any way it would be to stop passing in a dummy 
value for fromlist, not stop pulling from sys.modules. The official idiom for 
directly calling __import__() is::

  __import__(module_name)
  return sys.modules[module_name]

It just so happens PyImport_Import() is old enough to be using both the old 
idiom of a bogus fromlist item *and* been updated at some point to use the new 
idiom.

I would also strongly discourage you from replacing __import__. More and more 
code is using importlib and various importers to do things and so it might have 
unforeseen consequences. importlib.import_module() also relies on 
importlib.__import__, not builtins.__import__ so as more code switches to that 
function for dynamic importing it will lead to more imports not using an 
overridden __import__.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18812>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to