tox-dev / sphinx-autodoc-typehints

Type hints support for the Sphinx autodoc extension
MIT License
539 stars 101 forks source link

Ignore `rst_prolog` option for function documentation #425

Open g3n35i5 opened 5 months ago

g3n35i5 commented 5 months ago

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

gaborbernat commented 5 months ago

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

alexdlaird commented 4 months ago

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
gaborbernat commented 3 months ago

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

flying-sheep commented 3 months ago

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.