-
-
Notifications
You must be signed in to change notification settings - Fork 167
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
Conversation
numpydoc/numpydoc.py
Outdated
@@ -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) |
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 pass None
for options
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.
adopting
@@ -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 comment
The 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 obj
@@ -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 comment
The 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.
xref #184. Not strictly connected since this issue is connected with |
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.
I can confirm that this does not break my MNE build, which uses methods documented on the same page as the class itself, or my SciPy build (with the suggested change), which uses methods documented on their own page.
I started looking into whether or not this PR would allow me to (re-)simplify the SciPy doc build by undoing some changes I made to SciPy recently to work around the sorts of things mentioned in this PR (I think?). But if I remove the templates I had added for attribute.rst
and method.rst
in order to place :orphan:
tags at the top, and revert the tweaks I had made to class.rst
, I see the old warnings back again:
/home/larsoner/python/scipy/scipy/stats/_distn_infrastructure.py:docstring of scipy.stats.rv_histogram.var:1: WARNING: duplicate object description of scipy.stats.rv_histogram.var, other instance in /home/larsoner/python/scipy/doc/source/generated/scipy.stats.rv_histogram.rst, use :noindex: for one of them
...
/home/larsoner/python/scipy/doc/source/generated/scipy.LowLevelCallable.function.rst: WARNING: document isn't included in any toctree
Would you expect that these tweaks should no longer be necessary after this PR?
numpydoc/numpydoc.py
Outdated
@@ -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) |
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 pass None
for options
I think the "document isn't included in any toctree" is from numpydoc creating a document for methods but not linking it into a I don't see why |
This is just a peculiarity of how SciPy generates docs, as stats distribution docs are generated on the fly. When I revert my
But this existed before this PR, too, so I'm not too surprised it continues here. In any case, it looks like this does not simplify anything at the SciPy end. But it looks like it isn't really designed to, doesn't break the builds, and otherwise looks reasonable to me. |
@@ -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 or {}) |
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.
Is this an appropriate thing to do with already-supported options?
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.
At some point numpydoc should re-use the sphinx versions of the options (numpdoc_show_inherited_class_members
=> 'inherited_members') rather than duplicate them, so I would claim it is not only appropriate but desired
numpydoc/tests/test_numpydoc.py
Outdated
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, but it works because 'upper' in 'upper' => True
. fixing
Co-Authored-By: mattip <[email protected]>
Thanks @mattip ! |
Thanks for the quick review |
numpydoc adds member docstrings in calls to
get_doc_object
, in bothmangle_docstrings
andmangle_signature
. A feature of numpydoc is that class methods get their own html page and the method in the class table is a link to that page. However, the automatic toctree generation in anautoclass
directive does not add the directorygenerated
to the toctree, resulting inreferences to unknown document
warnings for each method. The only solution I could find was to use:exclude-members:
on theautoclass
directive. I modified the logic insideget_doc_object
to handle both the:members:
and:exclude-members:
options. Tests added. Here is an example