Constances in autodoc

258 views
Skip to first unread message

Louis King

unread,
Jun 26, 2021, 7:05:33 PM6/26/21
to sphinx-users

All, I realize in python, a constant is really just a state of mind but I would like to document them.
When I give a constant an all caps name i.e. VERBOSE in a module or class sphinx/autodoc does identify them with bold text name, following the docstring.
VERBOSE = True
I would like to add documentation, what it is and how it us used as with variables or  arguments.

Currently I am using :cvar ... to document constants, but that is less than ideal.
Am I missing something? Others have a better idea?

Komiya Takeshi

unread,
Jun 27, 2021, 9:55:15 AM6/27/21
to sphinx...@googlegroups.com
Hi,

How about using `#:` style comment for the constant?
https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#directive-automethod

Thanks,
Takeshi KOMIYA

2021年6月27日(日) 8:05 Louis King <ag20...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups "sphinx-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sphinx-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sphinx-users/d3745971-c225-4e94-a853-acfe94b4a11fn%40googlegroups.com.

Louis King

unread,
Jun 27, 2021, 7:04:18 PM6/27/21
to sphinx-users

Takeshi KOMIYA thanks for the pointer. just what I was looking for. thnaks.

Louis King

unread,
Aug 29, 2022, 10:12:02 PM8/29/22
to sphinx-users
A year later and the project continues and I am still trying to get the documentation right. And having another issue with variables ( #: ).

Within module fan I have Class Run. Within class Run I have declared and documented #: some constants. This is good and they show up in the Sphinx output.  Also within Class Run is a function _main() and in _main() is declared a constant/variable _yellow of type dict.

The bad news is that #: documentation for this constant and how it is used, locally withing function _main(), does not appear in the sphinx/autodoc output. I have tried 1) #: documentation before the constant, 2) #: inline following the constant, 3) docstring on the line following the constant.  None of these appear in the the html output.

My python code looks like the #: example following.  https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#directive-autodata  I have tried adding a #: to the __init__ like the example to no effect.

Without making all the related files available online, any obvious thing I am missing? No problem displaying the files. Just don't want to throw all the spaghetti at the wall, unless I need to.
Reply all
Reply to author
Forward
0 new messages