sphinx-extensions2 / sphinx-autodoc2

A Sphinx extension that automatically generates API documentation for your Python packages.
https://sphinx-autodoc2.readthedocs.io
MIT License
70 stars 9 forks source link

Support autodoc_typehints setting #21

Open blink1073 opened 1 year ago

blink1073 commented 1 year ago

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.

caseyjconger commented 1 year ago

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

chrisjsewell commented 7 months ago

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

mm21 commented 4 months ago

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.)