sphinx-autodoc-typehints icon indicating copy to clipboard operation
sphinx-autodoc-typehints copied to clipboard

Ignore `rst_prolog` option for function documentation

Open g3n35i5 opened this issue 1 year ago • 4 comments

Since https://github.com/tox-dev/sphinx-autodoc-typehints/pull/422/ has been merged , the function documentation contains the rst_prolog option text.

The rst_prolog option is automatically inserted at the beginning of each source file read. I currently use it to globally limit the toc tree depth.

With the changes in https://github.com/tox-dev/sphinx-autodoc-typehints/pull/422/, the documentation of the individual functions is written to temporary rst files and then evaluated, as far as I understand it. This ensures that sphinx inserts the rst_prolog value and sphinx-autodoc-typehints seems to interpret this value not as an rst directive but as a string.

# Set maximum depth for the right sidebar content overview
rst_prolog = ":tocdepth: 3"

Selection_20240208_01

g3n35i5 avatar Feb 08 '24 08:02 g3n35i5

PR with a fix is welcome (with tests). Thanks!

gaborbernat avatar Feb 08 '24 14:02 gaborbernat

Similarly, adding any sort of replacement in conf.py

rst_prolog = """
.. |pyngrok_version| replace:: {pyngrok_version}
""".format(pyngrok_version=version)

replaces every typedoc hint, whether it matches the replacement string or not (in this case, version is 7.1.5):

311511175-9030faf9-2f7d-44f4-903a-c16167378448 311511176-f018d23a-082e-4d75-9f1c-9534b284c318

Presumably it's finding the union | operator too greedily. Here's how the docs should look: https://pyngrok.readthedocs.io/en/latest/api.html#module-pyngrok.ngrok

Solution until this is fixed is to pin back the version:

sphinx_autodoc_typehints==1.25.2

alexdlaird avatar Mar 10 '24 16:03 alexdlaird

@flying-sheep can you take a look at this regression?

gaborbernat avatar Mar 11 '24 16:03 gaborbernat

Should be simple: https://github.com/tox-dev/sphinx-autodoc-typehints/pull/436

The RSTParser class we use has a dedicated method to add pro- and epilogue. We can just replace that with something that does nothing.

You just need to add a test and it should be ready to go.

flying-sheep avatar Mar 12 '24 09:03 flying-sheep