mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #6709: autodoc: mock object does not work as a class decorator
This commit is contained in:
parent
73a93f897e
commit
59336da8bd
1
CHANGES
1
CHANGES
@ -24,6 +24,7 @@ Bugs fixed
|
|||||||
|
|
||||||
.. _latex3/latex2e#173: https://github.com/latex3/latex2e/issues/173
|
.. _latex3/latex2e#173: https://github.com/latex3/latex2e/issues/173
|
||||||
* #6618: LaTeX: Avoid section names at the end of a page
|
* #6618: LaTeX: Avoid section names at the end of a page
|
||||||
|
* #6709: autodoc: mock object does not work as a class decorator
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
@ -60,7 +60,7 @@ class _MockObject:
|
|||||||
return _make_subclass(key, self.__display_name__, self.__class__)()
|
return _make_subclass(key, self.__display_name__, self.__class__)()
|
||||||
|
|
||||||
def __call__(self, *args, **kw) -> Any:
|
def __call__(self, *args, **kw) -> Any:
|
||||||
if args and type(args[0]) in [FunctionType, MethodType]:
|
if args and type(args[0]) in [type, FunctionType, MethodType]:
|
||||||
# Appears to be a decorator, pass through unchanged
|
# Appears to be a decorator, pass through unchanged
|
||||||
return args[0]
|
return args[0]
|
||||||
return self
|
return self
|
||||||
|
@ -96,3 +96,24 @@ def test_abc_MockObject():
|
|||||||
assert isinstance(obj, Base)
|
assert isinstance(obj, Base)
|
||||||
assert isinstance(obj, _MockObject)
|
assert isinstance(obj, _MockObject)
|
||||||
assert isinstance(obj.some_method(), Derived)
|
assert isinstance(obj.some_method(), Derived)
|
||||||
|
|
||||||
|
|
||||||
|
def test_mock_decorator():
|
||||||
|
mock = _MockObject()
|
||||||
|
|
||||||
|
@mock.function_deco
|
||||||
|
def func():
|
||||||
|
"""docstring"""
|
||||||
|
|
||||||
|
class Foo:
|
||||||
|
@mock.method_deco
|
||||||
|
def meth(self):
|
||||||
|
"""docstring"""
|
||||||
|
|
||||||
|
@mock.class_deco
|
||||||
|
class Bar:
|
||||||
|
"""docstring"""
|
||||||
|
|
||||||
|
assert func.__doc__ == "docstring"
|
||||||
|
assert Foo.meth.__doc__ == "docstring"
|
||||||
|
assert Bar.__doc__ == "docstring"
|
||||||
|
Loading…
Reference in New Issue
Block a user