]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
pydoc.safeimport: Use importlib.import_module instead of __import__ (GH-103118)
authorYuxin Wu <ppwwyyxxc@gmail.com>
Wed, 3 May 2023 23:26:39 +0000 (07:26 +0800)
committerGitHub <noreply@github.com>
Wed, 3 May 2023 23:26:39 +0000 (16:26 -0700)
Lib/pydoc.py

index b10a5da99402b5b5b39d7378f62c2207ad6a701b..84e673a7f87f90768e1fcda601b41e385f6e5b4c 100755 (executable)
@@ -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