Skip to content

pydoc.safeimport: Use importlib.import_module instead of __import__ #103118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Lib/pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def safeimport(path, forceload=0, cache={}):
# Prevent garbage collection.
cache[key] = sys.modules[key]
del sys.modules[key]
module = __import__(path)
module = importlib.import_module(path)
except BaseException as err:
# Did the error occur before or after the module was found?
if path in sys.modules:
Expand All @@ -463,9 +463,6 @@ def safeimport(path, forceload=0, cache={}):
else:
# Some other error occurred during the importing process.
raise ErrorDuringImport(path, err)
for part in path.split('.')[1:]:
try: module = getattr(module, part)
except AttributeError: return None
return module

# ---------------------------------------------------- formatter base class
Expand Down