BUG: autosummary to list all class members

This commit is contained in:
Joris Van den Bossche 2017-11-17 09:45:01 +01:00
parent 931148eadb
commit 098add17f6
3 changed files with 12 additions and 6 deletions

View File

@ -159,7 +159,7 @@ def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
except TemplateNotFound: except TemplateNotFound:
template = template_env.get_template('autosummary/base.rst') 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 # type: (Any, unicode, List[unicode], bool) -> Tuple[List[unicode], List[unicode]] # NOQA
items = [] # type: List[unicode] items = [] # type: List[unicode]
for name in dir(obj): for name in dir(obj):
@ -169,9 +169,7 @@ def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
continue continue
documenter = get_documenter(value, obj) documenter = get_documenter(value, obj)
if documenter.objtype == typ: if documenter.objtype == typ:
if typ == 'method': if imported or getattr(value, '__module__', None) == obj.__name__:
items.append(name)
elif imported or getattr(value, '__module__', None) == obj.__name__:
# skip imported members if expected # skip imported members if expected
items.append(name) items.append(name)
public = [x for x in items public = [x for x in items
@ -191,9 +189,9 @@ def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
elif doc.objtype == 'class': elif doc.objtype == 'class':
ns['members'] = dir(obj) ns['members'] = dir(obj)
ns['methods'], ns['all_methods'] = \ ns['methods'], ns['all_methods'] = \
get_members(obj, 'method', ['__init__'], imported=imported_members) get_members(obj, 'method', ['__init__'])
ns['attributes'], ns['all_attributes'] = \ ns['attributes'], ns['all_attributes'] = \
get_members(obj, 'attribute', imported=imported_members) get_members(obj, 'attribute')
parts = name.split('.') parts = name.split('.')
if doc.objtype in ('method', 'attribute'): if doc.objtype in ('method', 'attribute'):

View File

@ -7,3 +7,7 @@ class Foo:
def bar(self): def bar(self):
pass pass
@property
def baz(self):
pass

View File

@ -145,6 +145,10 @@ def test_autosummary_generate(app, status, warning):
' ~Foo.__init__\n' ' ~Foo.__init__\n'
' ~Foo.bar\n' ' ~Foo.bar\n'
' \n' in Foo) ' \n' in Foo)
assert (' .. autosummary::\n'
' \n'
' ~Foo.baz\n'
' \n' in Foo)
def test_import_by_name(): def test_import_by_name():