From f8200bdddc4a84cabd656cf0bd9ae185fa703857 Mon Sep 17 00:00:00 2001 From: Michael Leinartas Date: Wed, 19 Oct 2016 16:20:16 -0500 Subject: [PATCH 1/2] Autodoc: Allow mocked module decorators to pass-through --- sphinx/ext/autodoc.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py index 6a1d907fd..a936fdddd 100644 --- a/sphinx/ext/autodoc.py +++ b/sphinx/ext/autodoc.py @@ -93,6 +93,9 @@ class _MockModule(object): self.__all__ = [] def __call__(self, *args, **kwargs): + if args and type(args[0]) in [FunctionType, MethodType]: + # Appears to be a decorator, pass through unchanged + return args[0] return _MockModule() def _append_submodule(self, submod): From 7943da940832147f60c6d59c58d693464e77f513 Mon Sep 17 00:00:00 2001 From: Michael Leinartas Date: Fri, 21 Oct 2016 09:53:25 -0500 Subject: [PATCH 2/2] Add tests for mocked modules --- tests/root/autodoc_missing_imports.py | 9 +++++++++ tests/test_autodoc.py | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/tests/root/autodoc_missing_imports.py b/tests/root/autodoc_missing_imports.py index 7a7173452..0901ce8e2 100644 --- a/tests/root/autodoc_missing_imports.py +++ b/tests/root/autodoc_missing_imports.py @@ -5,5 +5,14 @@ import missing_package1.missing_module1 from missing_package2 import missing_module2 from missing_package3.missing_module3 import missing_name +@missing_name +def decoratedFunction(): + """decoratedFunction docstring""" + return None + class TestAutodoc(object): """TestAutodoc docstring.""" + @missing_name + def decoratedMethod(self): + """TestAutodoc::decoratedMethod docstring""" + return None diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py index d290e050b..052c5f573 100644 --- a/tests/test_autodoc.py +++ b/tests/test_autodoc.py @@ -832,6 +832,17 @@ def test_generate(): assert_result_contains(' .. py:method:: CustomDataDescriptor.meth()', 'module', 'test_autodoc') + # test mocked module imports + options.members = ['TestAutodoc'] + options.undoc_members = False + assert_result_contains('.. py:class:: TestAutodoc', + 'module', 'autodoc_missing_imports') + assert_result_contains(' .. py:method:: TestAutodoc.decoratedMethod()', + 'module', 'autodoc_missing_imports') + options.members = ['decoratedFunction'] + assert_result_contains('.. py:function:: decoratedFunction()', + 'module', 'autodoc_missing_imports') + # --- generate fodder ------------ __all__ = ['Class']