From 59336da8bd844daedcc058ce5fe0b148967a882b Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 6 Oct 2019 23:31:07 +0900 Subject: [PATCH] Fix #6709: autodoc: mock object does not work as a class decorator --- CHANGES | 1 + sphinx/ext/autodoc/mock.py | 2 +- tests/test_ext_autodoc_mock.py | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 7a5c28d46..a02fb9bd0 100644 --- a/CHANGES +++ b/CHANGES @@ -24,6 +24,7 @@ Bugs fixed .. _latex3/latex2e#173: https://github.com/latex3/latex2e/issues/173 * #6618: LaTeX: Avoid section names at the end of a page +* #6709: autodoc: mock object does not work as a class decorator Testing -------- diff --git a/sphinx/ext/autodoc/mock.py b/sphinx/ext/autodoc/mock.py index 4f534a452..7fa4627a6 100644 --- a/sphinx/ext/autodoc/mock.py +++ b/sphinx/ext/autodoc/mock.py @@ -60,7 +60,7 @@ class _MockObject: return _make_subclass(key, self.__display_name__, self.__class__)() 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 return args[0] return self diff --git a/tests/test_ext_autodoc_mock.py b/tests/test_ext_autodoc_mock.py index 5562f47de..04bff11ae 100644 --- a/tests/test_ext_autodoc_mock.py +++ b/tests/test_ext_autodoc_mock.py @@ -96,3 +96,24 @@ def test_abc_MockObject(): assert isinstance(obj, Base) assert isinstance(obj, _MockObject) 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"