diff options
Diffstat (limited to 'sphinx/ext/autodoc/importer.py')
-rw-r--r-- | sphinx/ext/autodoc/importer.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/sphinx/ext/autodoc/importer.py b/sphinx/ext/autodoc/importer.py index 00a55c4c5..e3bf1560c 100644 --- a/sphinx/ext/autodoc/importer.py +++ b/sphinx/ext/autodoc/importer.py @@ -23,7 +23,7 @@ from sphinx.util.inspect import isenumclass, safe_getattr if False: # For type annotation - from typing import Any, Callable, Dict, Generator, List, Optional # NOQA + from typing import Any, Callable, Dict, Generator, List, Optional, Tuple # NOQA logger = logging.getLogger(__name__) @@ -31,6 +31,14 @@ logger = logging.getLogger(__name__) class _MockObject(object): """Used by autodoc_mock_imports.""" + def __new__(cls, *args, **kwargs): + # type: (Any, Any) -> Any + if len(args) == 3 and isinstance(args[1], tuple) and args[1][-1].__class__ is cls: + # subclassing MockObject + return type(args[0], (_MockObject,), args[2], **kwargs) # type: ignore + else: + return super(_MockObject, cls).__new__(cls) + def __init__(self, *args, **kwargs): # type: (Any, Any) -> None pass @@ -47,6 +55,10 @@ class _MockObject(object): # type: () -> None pass + def __mro_entries__(self, bases): + # type: (Tuple) -> Tuple + return bases + def __getitem__(self, key): # type: (str) -> _MockObject return self |