mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #3071 from mleinart/autodoc/pass_through_decorators
Autodoc: Allow mocked module decorators to pass-through functions unchanged
This commit is contained in:
commit
b32d9a9bc7
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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']
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user