Skip to content

Add option to use member listing for attributes #161

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

Merged
merged 6 commits into from
Apr 17, 2019
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
5 changes: 5 additions & 0 deletions doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ numpydoc_use_blockquotes : bool
Until version 0.8, parameter definitions were shown as blockquotes, rather
than in a definition list. If your styling requires blockquotes, switch
this config option to True. This option will be removed in version 0.10.
numpydoc_attributes_as_param_list : bool
Whether to format the Attributes section of a class page in the same way
as the Parameter section. If it's False, the Attributes section will be
formatted as the Methods section using an autosummary table.
``True`` by default.
numpydoc_edit_link : bool
.. deprecated:: edit your HTML template instead

Expand Down
7 changes: 5 additions & 2 deletions numpydoc/docscrape_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def load_config(self, config):
self.use_plots = config.get('use_plots', False)
self.use_blockquotes = config.get('use_blockquotes', False)
self.class_members_toctree = config.get('class_members_toctree', True)
self.attributes_as_param_list = config.get('attributes_as_param_list', True)
self.template = config.get('template', None)
if self.template is None:
template_dirs = [os.path.join(os.path.dirname(__file__), 'templates')]
Expand Down Expand Up @@ -384,8 +385,10 @@ def __str__(self, indent=0, func_role="obj"):
'notes': self._str_section('Notes'),
'references': self._str_references(),
'examples': self._str_examples(),
'attributes': self._str_param_list('Attributes',
fake_autosummary=True),
'attributes':
self._str_param_list('Attributes', fake_autosummary=True)
if self.attributes_as_param_list
else self._str_member_list('Attributes'),
'methods': self._str_member_list('Methods'),
}
ns = dict((k, '\n'.join(v)) for k, v in ns.items())
Expand Down
5 changes: 4 additions & 1 deletion numpydoc/numpydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ def mangle_docstrings(app, what, name, obj, options, lines):
'show_class_members': app.config.numpydoc_show_class_members,
'show_inherited_class_members':
app.config.numpydoc_show_inherited_class_members,
'class_members_toctree': app.config.numpydoc_class_members_toctree}
'class_members_toctree': app.config.numpydoc_class_members_toctree,
'attributes_as_param_list':
app.config.numpydoc_attributes_as_param_list}

cfg.update(options or {})
u_NL = sixu('\n')
Expand Down Expand Up @@ -227,6 +229,7 @@ def setup(app, get_doc_object_=get_doc_object):
app.add_config_value('numpydoc_show_inherited_class_members', True, True)
app.add_config_value('numpydoc_class_members_toctree', True, True)
app.add_config_value('numpydoc_citation_re', '[a-z0-9_.-]+', True)
app.add_config_value('numpydoc_attributes_as_param_list', True, True)

# Extra mangling domains
app.add_domain(NumpyPythonDomain)
Expand Down
37 changes: 37 additions & 0 deletions numpydoc/tests/test_docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,43 @@ def no_period(self):
""")


def test_class_attributes_as_member_list():

class Foo:
"""
Class docstring.

Attributes
----------
an_attribute
Another description that is not used.

"""
@property
def an_attribute(self):
"""Test attribute"""
return None

attr_doc = """:Attributes:

:obj:`an_attribute <an_attribute>`
Test attribute"""

assert attr_doc in str(SphinxClassDoc(Foo))
assert "Another description" not in str(SphinxClassDoc(Foo))

attr_doc2 = """.. rubric:: Attributes

.. autosummary::
:toctree:

an_attribute"""

cfg = dict(attributes_as_param_list=False)
assert attr_doc2 in str(SphinxClassDoc(Foo, config=cfg))
assert "Another description" not in str(SphinxClassDoc(Foo, config=cfg))


def test_templated_sections():
doc = SphinxClassDoc(None, class_doc_txt,
config={'template': jinja2.Template('{{examples}}\n{{parameters}}')})
Expand Down
1 change: 1 addition & 0 deletions numpydoc/tests/test_numpydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class MockConfig():
templates_path = []
numpydoc_edit_link = False
numpydoc_citation_re = '[a-z0-9_.-]+'
numpydoc_attributes_as_param_list = True

class MockBuilder():
config = MockConfig()
Expand Down