diff options
author | Yuxin Wu <ppwwyyxxc@gmail.com> | 2023-05-03 23:26:39 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-03 23:26:39 (GMT) |
commit | e95dd40aff35775efce4c03bec7d82f03711310b (patch) | |
tree | 63da00ba93e743db43cbbfba2c20c362da366f9c /Lib/pydoc.py | |
parent | d6e83fbf30fb25996b547d8a2444814437e228e5 (diff) | |
download | cpython-e95dd40aff35775efce4c03bec7d82f03711310b.zip cpython-e95dd40aff35775efce4c03bec7d82f03711310b.tar.gz cpython-e95dd40aff35775efce4c03bec7d82f03711310b.tar.bz2 |
pydoc.safeimport: Use importlib.import_module instead of __import__ (GH-103118)
Diffstat (limited to 'Lib/pydoc.py')
-rwxr-xr-x | Lib/pydoc.py | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py index b10a5da..84e673a 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 |