autodoc: Fix enable mocks on importing module

This commit is contained in:
Takeshi KOMIYA
2020-12-21 01:32:50 +09:00
parent d7c490fefc
commit edc7f23620

View File

@@ -1809,12 +1809,14 @@ class UninitializedGlobalVariableMixin(DataDocumenterMixinBase):
except ImportError as exc:
# annotation only instance variable (PEP-526)
try:
parent = importlib.import_module(self.modname)
annotations = get_type_hints(parent, None, self.config.autodoc_type_aliases)
if self.objpath[-1] in annotations:
self.object = UNINITIALIZED_ATTR
self.parent = parent
return True
with mock(self.config.autodoc_mock_imports):
parent = importlib.import_module(self.modname)
annotations = get_type_hints(parent, None,
self.config.autodoc_type_aliases)
if self.objpath[-1] in annotations:
self.object = UNINITIALIZED_ATTR
self.parent = parent
return True
except ImportError:
pass