Skip to content

Commit e95dd40

Browse files
authored
pydoc.safeimport: Use importlib.import_module instead of __import__ (GH-103118)
1 parent d6e83fb commit e95dd40

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

Lib/pydoc.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ def safeimport(path, forceload=0, cache={}):
448448
# Prevent garbage collection.
449449
cache[key] = sys.modules[key]
450450
del sys.modules[key]
451-
module = __import__(path)
451+
module = importlib.import_module(path)
452452
except BaseException as err:
453453
# Did the error occur before or after the module was found?
454454
if path in sys.modules:
@@ -463,9 +463,6 @@ def safeimport(path, forceload=0, cache={}):
463463
else:
464464
# Some other error occurred during the importing process.
465465
raise ErrorDuringImport(path, err)
466-
for part in path.split('.')[1:]:
467-
try: module = getattr(module, part)
468-
except AttributeError: return None
469466
return module
470467

471468
# ---------------------------------------------------- formatter base class

0 commit comments

Comments
 (0)