diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2016-11-02 23:01:16 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-02 23:01:16 +0900 |
commit | b32d9a9bc7d19eb6ba2dfaaf3c08b1e587c441cb (patch) | |
tree | 1e1cc88736ed626a44ffb566612daa9fab7a38ef | |
parent | 1777939fa49b8d43b72e2c962df991b265aec664 (diff) | |
parent | 7943da940832147f60c6d59c58d693464e77f513 (diff) | |
download | sphinx-git-b32d9a9bc7d19eb6ba2dfaaf3c08b1e587c441cb.tar.gz |
Merge pull request #3071 from mleinart/autodoc/pass_through_decorators
Autodoc: Allow mocked module decorators to pass-through functions unchanged
-rw-r--r-- | sphinx/ext/autodoc.py | 3 | ||||
-rw-r--r-- | tests/root/autodoc_missing_imports.py | 9 | ||||
-rw-r--r-- | tests/test_autodoc.py | 11 |
3 files changed, 23 insertions, 0 deletions
diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py index 98783cfdb..148c09811 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): 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 68e15bbed..2b5d80efb 100644 --- a/tests/test_autodoc.py +++ b/tests/test_autodoc.py @@ -853,6 +853,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'] |