-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Improve autodata docstring detection #6495
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
Comments
It might be related to the troubles of #857 btw |
Reasonable. But it is hard to get the original location of the variable. |
Yes I think the easiest would be to rely on :annotation:, but offer a parameter to "repr()" the variable anyway (useful to autodocument default settings and the likes), wouldn't it ? |
I think most difficult thing is obtaining comment for the variable. How to rendering is not problem in this case. What do you mean "easy"? |
I mean the ":annotation:" parameter in RST sources seems good enough, imho, to provide documentation for the data when the original docstring can't be found directly in python source. |
It's not good idea. The If you can write
You don't need to use any workaround for this. |
Alright I was mislead by the sphinx docs mentioning "autodata" : http://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#directive-autoattribute Maybe the doc should be updated to reflect what you just wrote? But I'm still a bit confused about the real usecases for :annotation:, so I wouldn't know how to turn it exactly. Anyway putting a document body lets the repr() visible in sphinx docs, so it's perfect for my current usecase. |
Ah, sorry. My last comment was wrong.
And I pushed a PR #6530 to fix the document. I hope this helps you. I guess no |
Looks good to me :) |
doc: Update document for :annotation: option (refs: #6495)
Thank you for reviewing! |
I'd just add one thing that I haven't seen discussed (here or elsewhere): if importing a variable that's type hinted, the type's docstring is what Sphinx displays (not the repr()). Example from package
Then in my documentation if I try to use but if I use I presume this is due to the difficulty finding where the variable is actually located. In any case I figured it was closely enough related to the original issue to mention here. |
I agree with @kconnour: using Even if you explicitly import your constants in # pkg/__init__.py
from pkg.constants import foo And even if you use alternative docstring comments: #: My docstring for foo
foo: float = 12.34 Is there a way to extract correctly the docstring, or tell to sphinx where exactly is the constant (with hiding the real path)? Thank you for your help. EDIT: In the previous example, this would give: .. autodata:: pkg.constants::foo
:modpath: pkg.foo However, this is quite ugly. |
Sphinx cannot find the docstring corresponding to a constant unless you point it to the exact file where it is, since it doesn't actually live on the object itself. See sphinx-doc/sphinx#6495 Fixes data-apis#601
Also it would not work if this is done through autosummary and not autodata, see #12020 |
Currently, if a variable (eg. a data dict MY_VARIABLE) is imported from a submodule to a parent module, and that an "autodata" pointing to the parent module's MY_VARIABLE is added to documentation, the initial MY_VARIABLE's docstrings (eg. "#: stuffs" is lost. It doesn't seem possible to add this docstring near the "from submodule import MY_VARIABLE).
Autodata "annotation" can be used to workaround this, but in this case the repr() of the variable (that I wanted to be in docs) doesn't appear anymore.
It would be nice for sphinx to follow imports and find the docstring of imported variables, or that it uses a force-injected "doc" one would put in such variables (I tried, it didn't work), or that there is a way to force a display of the repr() of a variable.
The text was updated successfully, but these errors were encountered: