Skip to content

Commit

Permalink
Merge pull request #3071 from mleinart/autodoc/pass_through_decorators
Browse files Browse the repository at this point in the history
Autodoc: Allow mocked module decorators to pass-through functions unchanged
  • Loading branch information
tk0miya committed Nov 2, 2016
2 parents 1777939 + 7943da9 commit b32d9a9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sphinx/ext/autodoc.py
Expand Up @@ -93,6 +93,9 @@ def __init__(self, *args, **kwargs):
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):
Expand Down
9 changes: 9 additions & 0 deletions tests/root/autodoc_missing_imports.py
Expand Up @@ -5,5 +5,14 @@
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
11 changes: 11 additions & 0 deletions tests/test_autodoc.py
Expand Up @@ -853,6 +853,17 @@ def assert_order(items, objtype, name, member_order, **kw):
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']

Expand Down

0 comments on commit b32d9a9

Please sign in to comment.