Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e95dd40

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

File tree

Expand file treeCollapse file tree

1 file changed

+1
-4
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+1
-4
lines changed

‎Lib/pydoc.py

Copy file name to clipboardExpand all lines: Lib/pydoc.py
+1-4Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.