From 6c275b80a954a50b6553b4026939935b82e00039 Mon Sep 17 00:00:00 2001 From: Yuxin Wu Date: Wed, 29 Mar 2023 12:01:35 -0700 Subject: [PATCH] pydoc.locate: Use importlib.import_module instead of __import__ --- Lib/pydoc.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 78d8fd5357f72a..0112ced48c580f 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -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: @@ -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