diff --git a/sphinx/ext/autosummary/generate.py b/sphinx/ext/autosummary/generate.py index 177d25e9d..e1dd1be51 100644 --- a/sphinx/ext/autosummary/generate.py +++ b/sphinx/ext/autosummary/generate.py @@ -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] diff --git a/tests/roots/test-ext-autosummary-skip-member/conf.py b/tests/roots/test-ext-autosummary-skip-member/conf.py index 7adf2eb1d..7c8f0e9cf 100644 --- a/tests/roots/test-ext-autosummary-skip-member/conf.py +++ b/tests/roots/test-ext-autosummary-skip-member/conf.py @@ -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): diff --git a/tests/roots/test-ext-autosummary-skip-member/target.py b/tests/roots/test-ext-autosummary-skip-member/target.py index aeef054e1..fdf557eee 100644 --- a/tests/roots/test-ext-autosummary-skip-member/target.py +++ b/tests/roots/test-ext-autosummary-skip-member/target.py @@ -8,3 +8,7 @@ class Foo: def skipmeth(self): """docstring of skipmeth.""" pass + + def _privatemeth(self): + """docstring of _privatemeth.""" + pass diff --git a/tests/test_ext_autosummary.py b/tests/test_ext_autosummary.py index 93b2fe9af..1948f6ae7 100644 --- a/tests/test_ext_autosummary.py +++ b/tests/test_ext_autosummary.py @@ -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',