From c994f30b25d70c30a675fb5786518108cec7cc78 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sun, 9 Dec 2018 12:28:01 -0800 Subject: [PATCH] Define _MockImporter as a MetaPathFinder The instance is added to sys.meta_path. Per the documentation, this should be a MetaPathFinder: https://docs.python.org/3/library/sys.html#sys.meta_path Correct the _MockImporter.find_module() type signature per typeshed. https://github.com/python/typeshed/blob/0b49ce75b478fdf283dda5dd1368759ac342dfe2/stdlib/3/importlib/abc.pyi#L56-L57 --- sphinx/ext/autodoc/importer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sphinx/ext/autodoc/importer.py b/sphinx/ext/autodoc/importer.py index 0b921e93f..ef2b9368d 100644 --- a/sphinx/ext/autodoc/importer.py +++ b/sphinx/ext/autodoc/importer.py @@ -98,7 +98,7 @@ class _MockModule(ModuleType): return o -class _MockImporter: +class _MockImporter(MetaPathFinder): def __init__(self, names): # type: (List[str]) -> None self.names = names @@ -120,7 +120,7 @@ class _MockImporter: del sys.modules[m] def find_module(self, name, path=None): - # type: (str, str) -> Any + # type: (str, Sequence[Union[bytes, str]]) -> Any # check if name is (or is a descendant of) one of our base_packages for n in self.names: if n == name or name.startswith(n + '.'):