diff options
author | Jon Dufresne <jon.dufresne@gmail.com> | 2019-08-17 11:45:39 -0700 |
---|---|---|
committer | Jon Dufresne <jon.dufresne@gmail.com> | 2019-08-17 11:45:39 -0700 |
commit | ecb1e763ad0917ac37061b648a53793a687cc760 (patch) | |
tree | da14d950c57dd801c1ac2d01995eaec574dcff4e /sphinx/ext/coverage.py | |
parent | bf573ae1454fd0a6f5bbcb316fbabc42a056da3a (diff) | |
download | sphinx-git-ecb1e763ad0917ac37061b648a53793a687cc760.tar.gz |
Switch uses of __import__ to importlib.get_module()
The Python docs for __import__ recommend using importlib.get_module().
https://docs.python.org/3/library/functions.html#__import__
> Note: This is an advanced function that is not needed in everyday
> Python programming, unlike importlib.import_module().
As importlib.get_module() uses the Python module cache and returns the
module, this also allows simplifying many module cache checks of use of
sys.modules.
importlib.get_module() has been available since Python 3.3.
Diffstat (limited to 'sphinx/ext/coverage.py')
-rw-r--r-- | sphinx/ext/coverage.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/sphinx/ext/coverage.py b/sphinx/ext/coverage.py index 24f51b856..7d53e7bb9 100644 --- a/sphinx/ext/coverage.py +++ b/sphinx/ext/coverage.py @@ -13,6 +13,7 @@ import glob import inspect import pickle import re +from importlib import import_module from os import path from typing import Any, Dict, IO, List, Pattern, Set, Tuple @@ -144,7 +145,7 @@ class CoverageBuilder(Builder): continue try: - mod = __import__(mod_name, fromlist=['foo']) + mod = import_module(mod_name) except ImportError as err: logger.warning(__('module %s could not be imported: %s'), mod_name, err) self.py_undoc[mod_name] = {'error': err} |