Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: autosummary to list all class members #4247

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions sphinx/ext/autosummary/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
except TemplateNotFound:
template = template_env.get_template('autosummary/base.rst')

def get_members(obj, typ, include_public=[], imported=False):
def get_members(obj, typ, include_public=[], imported=True):
# type: (Any, unicode, List[unicode], bool) -> Tuple[List[unicode], List[unicode]] # NOQA
items = [] # type: List[unicode]
for name in dir(obj):
Expand All @@ -169,9 +169,7 @@ def get_members(obj, typ, include_public=[], imported=False):
continue
documenter = get_documenter(value, obj)
if documenter.objtype == typ:
if typ == 'method':
items.append(name)
elif imported or getattr(value, '__module__', None) == obj.__name__:
if imported or getattr(value, '__module__', None) == obj.__name__:
# skip imported members if expected
items.append(name)
public = [x for x in items
Expand All @@ -191,9 +189,9 @@ def get_members(obj, typ, include_public=[], imported=False):
elif doc.objtype == 'class':
ns['members'] = dir(obj)
ns['methods'], ns['all_methods'] = \
get_members(obj, 'method', ['__init__'], imported=imported_members)
get_members(obj, 'method', ['__init__'])
ns['attributes'], ns['all_attributes'] = \
get_members(obj, 'attribute', imported=imported_members)
get_members(obj, 'attribute')

parts = name.split('.')
if doc.objtype in ('method', 'attribute'):
Expand Down
4 changes: 4 additions & 0 deletions tests/roots/test-ext-autosummary/autosummary_dummy_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ def __init__(self):

def bar(self):
pass

@property
def baz(self):
pass
4 changes: 4 additions & 0 deletions tests/test_ext_autosummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ def test_autosummary_generate(app, status, warning):
' ~Foo.__init__\n'
' ~Foo.bar\n'
' \n' in Foo)
assert (' .. autosummary::\n'
' \n'
' ~Foo.baz\n'
' \n' in Foo)


def test_import_by_name():
Expand Down