-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Open
Description
Describe the bug
In a project of mine, I use nanobind to bind classes and free functions and also sphinx to render the documentation.
While nanobind generated docstrings seems to respect PEP 257, sphinx autodoc signature rendering is OK for free functions but fails for class methods.
How to Reproduce
I did this minimal project to reproduce the bug: https://gitlab.inria.fr/vrouvrea/sphinx_nanobind_investigation
Free functions ✔️
hello_world
is a binded C++ function, sphinx autodoc signature rendering is OK:

nanobind produces the following docstring (OK with PEP 257):
from sphinx_nanobind_investigation import hello_world
help(hello_world)
# Help on nb_func in module sphinx_nanobind_investigation.hello_ext:
#
# hello_world = <nanobind.nb_func object>
# hello_world(nbr: int = 0) -> None
# ...
Class methods ❌
While for the C++ binded class Hello
it is not available:

nanobind produces the following docstring (also OK with PEP 257):
from sphinx_nanobind_investigation import Hello
help(Hello)
# class Hello(builtins.object)
# | Hello class
# |
# | Methods defined here:
# |
# | __init__(...)
# | __init__(self, arg: str, /) -> None
# |
# | name(...)
# | name(self) -> str
# ...
Environment Information
Platform: linux; (Linux-6.8.0-71-generic-x86_64-with-glibc2.39)
Python version: 3.13.5 | packaged by conda-forge | (main, Jun 16 2025, 08:27:50) [GCC 13.3.0])
Python implementation: CPython
Sphinx version: 8.2.3
Docutils version: 0.21.2
Jinja2 version: 3.1.6
Pygments version: 2.19.2
Sphinx extensions
["sphinx.ext.autodoc"]
Additional context
No response