From bcdea4da5cd46be8399ed979ab878cdc78469c5f Mon Sep 17 00:00:00 2001 From: Rouven Czerwinski Date: Wed, 24 Jan 2018 17:29:24 +0100 Subject: [PATCH] autodoc: prefer _MockImporter over other importers in sys.path In case we want to mock modules which are actually available in the current environment, we need to add the _MockImporter before other importers. We ran into this problem in our application, where importing the existing modules caused side effects which were not fixed by autodoc_mock_imports. --- sphinx/ext/autodoc/importer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/ext/autodoc/importer.py b/sphinx/ext/autodoc/importer.py index cea1c12bd..ee43784ca 100644 --- a/sphinx/ext/autodoc/importer.py +++ b/sphinx/ext/autodoc/importer.py @@ -87,7 +87,7 @@ class _MockImporter(object): self.names = names self.mocked_modules = [] # type: List[str] # enable hook by adding itself to meta_path - sys.meta_path = sys.meta_path + [self] + sys.meta_path.insert(0, self) def disable(self): # remove `self` from `sys.meta_path` to disable import hook