8000 Merge pull request #4247 from jorisvandenbossche/autosummary-attributes · sphinx-doc/sphinx@2994014 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2994014

Browse files
authored
Merge pull request #4247 from jorisvandenbossche/autosummary-attributes
BUG: autosummary to list all class members
2 parents 66bf89d + 098add1 commit 2994014

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

sphinx/ext/autosummary/generate.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
170170
except TemplateNotFound:
171171
template = template_env.get_template('autosummary/base.rst')
172172

173-
def get_members(obj, typ, include_public=[], imported=False):
173+
def get_members(obj, typ, include_public=[], imported=True):
174174
# type: (Any, unicode, List[unicode], bool) -> Tuple[List[unicode], List[unicode]] # NOQA
175175
items = [] # type: List[unicode]
176176
for name in dir(obj):
@@ -180,9 +180,7 @@ def get_members(obj, typ, include_public=[], imported=False):
180180
continue
181181
documenter = get_documenter(app, value, obj)
182182
if documenter.objtype == typ:
183-
if typ == 'method':
184-
items.append(name)
185-
elif imported or getattr(value, '__module__', None) == obj.__name__:
183+
if imported or getattr(value, '__module__', None) == obj.__name__:
186184
# skip imported members if expected
187185
items.append(name)
188186
public = [x for x in items
@@ -202,9 +200,9 @@ def get_members(obj, typ, include_public=[], imported=False):
202200
elif doc.objtype == 'class':
203201
ns['members'] = dir(obj)
204202
ns['methods'], ns['all_methods'] = \
205-
get_members(obj, 'method', ['__init__'], imported=imported_members)
203+
get_members(obj, 'method', ['__init__'])
206204
ns['attributes'], ns['all_attributes'] = \
207-
get_members(obj, 'attribute', imported=imported_members)
205+
get_members(obj, 'attribute')
208206

209207
parts = name.split('.')
210208
if doc.objtype in ('method', 'attribute'):

tests/roots/test-ext-autosummary/autosummary_dummy_module.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ def __init__(self):
77

88
def bar(self):
99
pass
10+
11+
@property
12+
def baz(self):
13+
pass

tests/test_ext_autosummary.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ def test_autosummary_generate(app, status, warning):
153153
' ~Foo.__init__\n'
154154
' ~Foo.bar\n'
155155
' \n' in Foo)
156+
assert (' .. autosummary::\n'
157+
' \n'
158+
' ~Foo.baz\n'
159+
' \n' in Foo)
156160

157161

158162
def test_import_by_name():

0 commit comments

Comments
 (0)
0