autodoc and optional parameters

848 views
Skip to first unread message

dleach

unread,
Jul 4, 2012, 6:43:31 PM7/4/12
to sphin...@googlegroups.com
How do I get autodoc to highlight the optional parameters?

The standard python documentation seems to use brackets ('[]') around the optional parameters. Consider the following method defined in my zork.py module:

def zorky(a,b=none):

def zorkz(a,b=none, c=none):

Now what gets generated in html is:

zork.zorky(a,b=none)

zork.zorkz(a, b=none, c=none)

what I would like though is:

zork.zorky(a[, b=none])
zork.zorky(a[, b=none[, c=none]])




Kevin Hunter

unread,
Jul 4, 2012, 7:09:47 PM7/4/12
to Sphinx Mailing List
At 6:43pm -0400 Wed, 04 Jul 2012, Dleach wrote:
> How do I get autodoc to highlight the optional parameters?
>
> The standard python documentation seems to use brackets ('[]') around
> the optional parameters. Consider the following method defined in my
> zork.py module:

> what I would like though is:
>
> zork.zorky(a[, b=none])
> zork.zorky(a[, b=none[, c=none]])

I hear your pain, but I don't think there's an elegant solution. I
would love to be do this, and asked a similar question a few days ago to
the tune of crickets:

https://groups.google.com/d/topic/sphinx-dev/TfY7zRII05c/discussion

I'm only aware of these four options:

.. automodule::
This pretty much does the entire file

.. autoclass::
This does a single class

.. autofunction::
This does a single function

.. function::
This does exactly and only what you write in this very space, with
the exception that it adds the CSS specific code (or whatever's
appropriate for the final documentation form). Meaning, you write
the documentation right here.

With autofunction, I've sinced learned it has only a single option:
':noindex:', which is not what I want or need.

Unfortunately, it looks like you either override everything (function::)
or nothing(auto...::), with little in-between. If you find otherwise,
I'd love to hear it.

Sorry mate,

Kevin

David Leach

unread,
Jul 4, 2012, 8:04:31 PM7/4/12
to sphin...@googlegroups.com, Sphinx Mailing List
Yeah, I was looking at the underlying code to autodoc and I think I see how to add support for this... But I'm not real proficient with python.

It looks like autodoc uses the inspect module to get a clean string of the function prototype. If you then use string functions to search for '=' you could do some addition search and replace to add '**[**' and '**]**' at the appropriate places...

Will give it a try and see what happens...
> --
> You received this message because you are subscribed to the Google Groups "sphinx-dev" group.
> To post to this group, send email to sphin...@googlegroups.com.
> To unsubscribe from this group, send email to sphinx-dev+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sphinx-dev?hl=en.
>

Stanisława Pałętka

unread,
Jul 5, 2012, 4:52:47 AM7/5/12
to sphin...@googlegroups.com
Nie mam dostępu

2012/7/5, dleach <tas...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "sphinx-dev" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sphinx-dev/-/KIPh7x--iCQJ.
Reply all
Reply to author
Forward
0 new messages