Skip to content

docs: document Sphinx autodoc handler for signature * (#4537) - #6144

Open
alisonpetersonhq wants to merge 4 commits into
pybind:masterfrom
alisonpetersonhq:fix/sphinx-signature-escape-4537
Open

docs: document Sphinx autodoc handler for signature * (#4537)#6144
alisonpetersonhq wants to merge 4 commits into
pybind:masterfrom
alisonpetersonhq:fix/sphinx-signature-escape-4537

Conversation

@alisonpetersonhq

@alisonpetersonhq alisonpetersonhq commented Aug 12, 2026

Copy link
Copy Markdown

Fixes #4537

Summary

  • Keep literal * in generated function signatures (needed by help(), stubgen, and autodoc_docstring_signature).
  • Document an autodoc-process-docstring handler in docs/advanced/misc.rst so Sphinx escapes * at doc-build time instead of changing the runtime docstring.

Test plan

  • Confirm generated signatures still contain literal *.
  • With the documented conf.py handler, Sphinx no longer warns on py::args / py::kw_only signatures.

📚 Documentation preview 📚: https://pybind11--6144.org.readthedocs.build/

Signed-off-by: alisonpetersonhq <alisonpetersonhq@users.noreply.github.com>
@henryiii

Copy link
Copy Markdown
Collaborator

I'm not sure this is correct, we'd need to make sure tools like stubgen support this.

This is a standard location for this information so I wonder if there's something sphinx could do (or has a config option for).

@henryiii

Copy link
Copy Markdown
Collaborator

It looks like the standard fix is to add an autodoc-process-docstring event handler in conf.py. The docstrings do need the literal *, that's a Python convention for builtins.

  • stubgen
  • pybind11-stubgen
  • autodoc_docstring_signature (in sphinx)
  • help() in Python

Signed-off-by: alisonpetersonhq <alisonpetersonhq@users.noreply.github.com>
Signed-off-by: alisonpetersonhq <alisonpetersonhq@users.noreply.github.com>
@alisonpetersonhq alisonpetersonhq changed the title Escape * in generated function signatures for Sphinx docs: document Sphinx autodoc handler for signature * (#4537) Aug 16, 2026
@alisonpetersonhq

Copy link
Copy Markdown
Author

Thanks @henryiii — switched approaches.

Kept the literal * in generated signatures (for help() / stubgen / autodoc_docstring_signature), reverted the C++ escape, and documented an autodoc-process-docstring handler in docs/advanced/misc.rst so Sphinx escapes * at doc-build time instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Use of pybind11::args or pybind11::kw_only results in a Sphinx warning due to the use of *

2 participants