-
-
Notifications
You must be signed in to change notification settings - Fork 169
ENH: accept autoclass member options #205
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,6 +132,7 @@ def mangle_docstrings(app, what, name, obj, options, lines): | |
app.config.numpydoc_show_inherited_class_members, | ||
'class_members_toctree': app.config.numpydoc_class_members_toctree} | ||
|
||
cfg.update(options) | ||
u_NL = sixu('\n') | ||
if what == 'module': | ||
# Strip top title | ||
|
@@ -177,7 +178,7 @@ def mangle_signature(app, what, name, obj, options, sig, retann): | |
|
||
if not hasattr(obj, '__doc__'): | ||
return | ||
doc = get_doc_object(obj) | ||
doc = get_doc_object(obj, config={'show_class_members': False}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We just want the signature at this point, not all the side effects of parsing all the members of |
||
sig = doc['Signature'] or getattr(obj, '__text_signature__', None) | ||
if sig: | ||
sig = re.sub(sixu("^[^(]*"), sixu(""), sig) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -796,11 +796,13 @@ class BadSection(object): | |
pass | ||
|
||
with warnings.catch_warnings(record=True) as w: | ||
warnings.filterwarnings('always', '', UserWarning) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure how test runs avoid the need for a filter to work properly, this is more in line with what numpy does. |
||
NumpyDocString(doc_text) | ||
assert len(w) == 1 | ||
assert "Unknown section Mope" == str(w[0].message) | ||
|
||
with warnings.catch_warnings(record=True) as w: | ||
warnings.filterwarnings('always', '', UserWarning) | ||
SphinxClassDoc(BadSection) | ||
assert len(w) == 1 | ||
assert('test_docscrape.test_unknown_section.<locals>.BadSection' | ||
|
@@ -1267,6 +1269,24 @@ def test_args_and_kwargs(): | |
Keyword arguments | ||
""") | ||
|
||
def test_autoclass(): | ||
cfg=dict(show_class_members=True, | ||
show_inherited_class_members=True) | ||
doc = SphinxClassDoc(str, ''' | ||
A top section before | ||
|
||
.. autoclass:: str | ||
''', config=cfg) | ||
line_by_line_compare(str(doc), r''' | ||
A top section before | ||
|
||
.. autoclass:: str | ||
|
||
.. rubric:: Methods | ||
|
||
|
||
''') | ||
|
||
|
||
if __name__ == "__main__": | ||
import pytest | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# -*- encoding:utf-8 -*- | ||
from __future__ import division, absolute_import, print_function | ||
|
||
from numpydoc.numpydoc import mangle_docstrings | ||
from sphinx.ext.autodoc import ALL | ||
|
||
class MockConfig(): | ||
numpydoc_use_plots = False | ||
numpydoc_use_blockquotes = True | ||
numpydoc_show_class_members = True | ||
numpydoc_show_inherited_class_members = True | ||
numpydoc_class_members_toctree = True | ||
templates_path = [] | ||
numpydoc_edit_link = False | ||
numpydoc_citation_re = '[a-z0-9_.-]+' | ||
|
||
class MockBuilder(): | ||
config = MockConfig() | ||
|
||
class MockApp(): | ||
config = MockConfig() | ||
builder = MockBuilder() | ||
translator = None | ||
|
||
|
||
app = MockApp() | ||
app.builder.app = app | ||
|
||
def test_mangle_docstrings(): | ||
s =''' | ||
A top section before | ||
|
||
.. autoclass:: str | ||
''' | ||
lines = s.split('\n') | ||
doc = mangle_docstrings(MockApp(), 'class', 'str', str, {}, lines) | ||
assert 'rpartition' in [x.strip() for x in lines] | ||
|
||
lines = s.split('\n') | ||
doc = mangle_docstrings(MockApp(), 'class', 'str', str, {'members':['upper']}, lines) | ||
mattip marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert 'rpartition' not in [x.strip() for x in lines] | ||
assert 'upper' in [x.strip() for x in lines] | ||
|
||
lines = s.split('\n') | ||
doc = mangle_docstrings(MockApp(), 'class', 'str', str, {'exclude-members': ALL}, lines) | ||
assert 'rpartition' not in [x.strip() for x in lines] | ||
assert 'upper' not in [x.strip() for x in lines] | ||
|
||
lines = s.split('\n') | ||
doc = mangle_docstrings(MockApp(), 'class', 'str', str, {'exclude-members': 'upper'}, lines) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is upper here intentionally a string and not a list of strings? are both meant to be supported? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really, but it works because |
||
assert 'rpartition' in [x.strip() for x in lines] | ||
assert 'upper' not in [x.strip() for x in lines] | ||
|
||
if __name__ == "__main__": | ||
import pytest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass the options on to
get_doc_object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To build the SciPy doc I had to change this to
cfg.update(options or {})
because in scipyoptdoc we passNone
for optionsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adopting