mirror of
https://github.com/python/cpython.git
synced 2025-08-23 10:16:01 +00:00
Close #15425: Eliminate more importlib related traceback noise
This commit is contained in:
parent
bb9b1c165d
commit
5ee9892406
5 changed files with 4275 additions and 4150 deletions
|
@ -1472,7 +1472,7 @@ def _find_and_load_unlocked(name, import_):
|
|||
parent = name.rpartition('.')[0]
|
||||
if parent:
|
||||
if parent not in sys.modules:
|
||||
import_(parent)
|
||||
_recursive_import(import_, parent)
|
||||
# Crazy side-effects!
|
||||
if name in sys.modules:
|
||||
return sys.modules[name]
|
||||
|
@ -1550,6 +1550,12 @@ def _gcd_import(name, package=None, level=0):
|
|||
_lock_unlock_module(name)
|
||||
return module
|
||||
|
||||
def _recursive_import(import_, name):
|
||||
"""Common exit point for recursive calls to the import machinery
|
||||
|
||||
This simplifies the process of stripping importlib from tracebacks
|
||||
"""
|
||||
return import_(name)
|
||||
|
||||
def _handle_fromlist(module, fromlist, import_):
|
||||
"""Figure out what __import__ should return.
|
||||
|
@ -1569,7 +1575,8 @@ def _handle_fromlist(module, fromlist, import_):
|
|||
fromlist.extend(module.__all__)
|
||||
for x in fromlist:
|
||||
if not hasattr(module, x):
|
||||
import_('{}.{}'.format(module.__name__, x))
|
||||
_recursive_import(import_,
|
||||
'{}.{}'.format(module.__name__, x))
|
||||
return module
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue