sphinx-autodoc2 icon indicating copy to clipboard operation
sphinx-autodoc2 copied to clipboard

Support autodoc_typehints setting

Open blink1073 opened this issue 2 years ago • 3 comments

The autodoc_typehints setting lets you put the type hints in the parameter list instead of the signature. This is also how https://github.com/tox-dev/sphinx-autodoc-typehints handles type hints, which can be a lot easier to read for complex function signatures.

blink1073 avatar Mar 13 '23 15:03 blink1073

I second this! I was just searching for how to do this after switching to autodoc2.

caseyjconger avatar May 09 '23 03:05 caseyjconger

I think an option to this makes sense 👍 Happy to recieve PRs

chrisjsewell avatar Nov 27 '23 07:11 chrisjsewell

I came up with a way to do this by hacking around in the docutils tree to copy the type hint nodes from the signature into the parameter list. I'm working on an extension to do the same thing by patching Sphinx where it generates the field list for parameters, which is a bit less hacky.

Here's an example of what it looks like: https://mm21.github.io/trilium-alchemy/build/autodoc2/trilium_alchemy/trilium_alchemy.core.html#trilium_alchemy.core.Session

It also changes the list from bullets to a definition list, which I find more clean and readable. The downside is it will only work reliably when there's exactly one signature.

(I may have also added the references to the default values, but can't remember now if that's a vanilla autodoc2 thing.)

mm21 avatar Feb 12 '24 04:02 mm21