mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
autosummary: Allows to document a member forcedly if skip-member handler returns False
This commit is contained in:
parent
66c3dd3adb
commit
491b19d6bb
@ -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] = [],
|
def get_members(obj: Any, types: Set[str], include_public: List[str] = [],
|
||||||
imported: bool = True) -> Tuple[List[str], List[str]]:
|
imported: bool = True) -> Tuple[List[str], List[str]]:
|
||||||
items = [] # type: List[str]
|
items = [] # type: List[str]
|
||||||
|
public = [] # type: List[str]
|
||||||
for name in dir(obj):
|
for name in dir(obj):
|
||||||
try:
|
try:
|
||||||
value = safe_getattr(obj, name)
|
value = safe_getattr(obj, name)
|
||||||
@ -160,10 +161,18 @@ def generate_autosummary_content(name: str, obj: Any, parent: Any,
|
|||||||
if documenter.objtype in types:
|
if documenter.objtype in types:
|
||||||
# skip imported members if expected
|
# skip imported members if expected
|
||||||
if imported or getattr(value, '__module__', None) == obj.__name__:
|
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)
|
items.append(name)
|
||||||
public = [x for x in items
|
public.append(name)
|
||||||
if x in include_public or not x.startswith('_')]
|
else:
|
||||||
|
items.append(name)
|
||||||
|
if name in include_public or not name.startswith('_'):
|
||||||
|
# considers member as public
|
||||||
|
public.append(name)
|
||||||
return public, items
|
return public, items
|
||||||
|
|
||||||
ns = {} # type: Dict[str, Any]
|
ns = {} # type: Dict[str, Any]
|
||||||
|
@ -12,6 +12,8 @@ autodoc_default_options = {'members': True}
|
|||||||
def skip_member(app, what, name, obj, skip, options):
|
def skip_member(app, what, name, obj, skip, options):
|
||||||
if name == 'skipmeth':
|
if name == 'skipmeth':
|
||||||
return True
|
return True
|
||||||
|
elif name == '_privatemeth':
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def setup(app):
|
def setup(app):
|
||||||
|
@ -8,3 +8,7 @@ class Foo:
|
|||||||
def skipmeth(self):
|
def skipmeth(self):
|
||||||
"""docstring of skipmeth."""
|
"""docstring of skipmeth."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def _privatemeth(self):
|
||||||
|
"""docstring of _privatemeth."""
|
||||||
|
pass
|
||||||
|
@ -315,6 +315,7 @@ def test_autosummary_skip_member(app):
|
|||||||
|
|
||||||
content = (app.srcdir / 'generate' / 'target.Foo.rst').text()
|
content = (app.srcdir / 'generate' / 'target.Foo.rst').text()
|
||||||
assert 'Foo.skipmeth' not in content
|
assert 'Foo.skipmeth' not in content
|
||||||
|
assert 'Foo._privatemeth' in content
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('dummy', testroot='ext-autosummary',
|
@pytest.mark.sphinx('dummy', testroot='ext-autosummary',
|
||||||
|
Loading…
Reference in New Issue
Block a user