mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #9657: autodoc: basecls for a subclass of mocked object is incorrect
This commit is contained in:
parent
a05dc0b419
commit
e79efef63a
1
CHANGES
1
CHANGES
@ -21,6 +21,7 @@ Bugs fixed
|
||||
* #9630: autodoc: Failed to build cross references if :confval:`primary_domain`
|
||||
is not 'py'
|
||||
* #9644: autodoc: Crashed on getting source info from problematic object
|
||||
* #9657: autodoc: The base class for a subclass of mocked object is incorrect
|
||||
* #9630: autosummary: Failed to build summary table if :confval:`primary_domain`
|
||||
is not 'py'
|
||||
|
||||
|
@ -26,6 +26,7 @@ class _MockObject:
|
||||
"""Used by autodoc_mock_imports."""
|
||||
|
||||
__display_name__ = '_MockObject'
|
||||
__name__ = ''
|
||||
__sphinx_mock__ = True
|
||||
__sphinx_decorator_args__: Tuple[Any, ...] = ()
|
||||
|
||||
@ -40,7 +41,7 @@ class _MockObject:
|
||||
return super().__new__(cls)
|
||||
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
self.__qualname__ = ''
|
||||
self.__qualname__ = self.__name__
|
||||
|
||||
def __len__(self) -> int:
|
||||
return 0
|
||||
@ -73,6 +74,7 @@ def _make_subclass(name: str, module: str, superclass: Any = _MockObject,
|
||||
attributes: Any = None, decorator_args: Tuple = ()) -> Any:
|
||||
attrs = {'__module__': module,
|
||||
'__display_name__': module + '.' + name,
|
||||
'__name__': name,
|
||||
'__sphinx_decorator_args__': decorator_args}
|
||||
attrs.update(attributes or {})
|
||||
|
||||
|
@ -17,6 +17,7 @@ from typing import (Any, Callable, Dict, Generator, List, NewType, Optional, Tup
|
||||
|
||||
import pytest
|
||||
|
||||
from sphinx.ext.autodoc import mock
|
||||
from sphinx.util.typing import restify, stringify
|
||||
|
||||
|
||||
@ -169,6 +170,12 @@ def test_restify_broken_type_hints():
|
||||
assert restify(BrokenType) == ':py:class:`tests.test_util_typing.BrokenType`'
|
||||
|
||||
|
||||
def test_restify_mock():
|
||||
with mock(['unknown']):
|
||||
import unknown
|
||||
assert restify(unknown.secret.Class) == ':py:class:`unknown.secret.Class`'
|
||||
|
||||
|
||||
def test_stringify():
|
||||
assert stringify(int) == "int"
|
||||
assert stringify(str) == "str"
|
||||
@ -293,3 +300,9 @@ def test_stringify_type_union_operator():
|
||||
|
||||
def test_stringify_broken_type_hints():
|
||||
assert stringify(BrokenType) == 'tests.test_util_typing.BrokenType'
|
||||
|
||||
|
||||
def test_stringify_mock():
|
||||
with mock(['unknown']):
|
||||
import unknown
|
||||
assert stringify(unknown.secret.Class) == 'unknown.secret.Class'
|
||||
|
Loading…
Reference in New Issue
Block a user