autosummary: Allows to document a member forcedly if skip-member handler returns False

This commit is contained in:
Takeshi KOMIYA 2019-11-16 18:15:53 +09:00
parent 66c3dd3adb
commit 491b19d6bb
4 changed files with 19 additions and 3 deletions

View File

@ -151,6 +151,7 @@ def generate_autosummary_content(name: str, obj: Any, parent: Any,
def get_members(obj: Any, types: Set[str], include_public: List[str] = [],
imported: bool = True) -> Tuple[List[str], List[str]]:
items = [] # type: List[str]
public = [] # type: List[str]
for name in dir(obj):
try:
value = safe_getattr(obj, name)
@ -160,10 +161,18 @@ def generate_autosummary_content(name: str, obj: Any, parent: Any,
if documenter.objtype in types:
# skip imported members if expected
if imported or getattr(value, '__module__', None) == obj.__name__:
if not skip_member(value, name, documenter.objtype):
skipped = skip_member(value, name, documenter.objtype)
if skipped is True:
pass
elif skipped is False:
# show the member forcedly
items.append(name)
public = [x for x in items
if x in include_public or not x.startswith('_')]
public.append(name)
else:
items.append(name)
if name in include_public or not name.startswith('_'):
# considers member as public
public.append(name)
return public, items
ns = {} # type: Dict[str, Any]

View File

@ -12,6 +12,8 @@ autodoc_default_options = {'members': True}
def skip_member(app, what, name, obj, skip, options):
if name == 'skipmeth':
return True
elif name == '_privatemeth':
return False
def setup(app):

View File

@ -8,3 +8,7 @@ class Foo:
def skipmeth(self):
"""docstring of skipmeth."""
pass
def _privatemeth(self):
"""docstring of _privatemeth."""
pass

View File

@ -315,6 +315,7 @@ def test_autosummary_skip_member(app):
content = (app.srcdir / 'generate' / 'target.Foo.rst').text()
assert 'Foo.skipmeth' not in content
assert 'Foo._privatemeth' in content
@pytest.mark.sphinx('dummy', testroot='ext-autosummary',