Skip to content

autodoc: automodule compatibility with nanobind #13868

@keltonhalbert

Description

@keltonhalbert

Describe the bug

I wasn't entirely sure if this should be under "bug" or "feature request", so please feel free to adjust the tag. I ultimately settled on "bug" because from the user-end, it's unexpected behavior.

The nanobind library for generating python bindings is a lighter-weight and more performant alternative offshoot of pybind11 from the same project author.

Currently, things like autofunction and autoclass work just fine with Sphinx. However, automodule fails to discover any functions (they have to be manually annotated). From the library author:

Some of the sphinx auto* tools don't recognize nanobind functions because they are based on a custom type nb_func instead of being a Python builtin or a C function.

I don't know if it further complicates things, but it also supports compiled submodules:

parent_module.submodule_1.function1
parent_module.submodule_2.function2

Functions and submodules are visible via dir(), and __all__ attributes can be created (though are not present by default). Currently, however, no functions are discoverable in modules or submodules unless manually annotated with autofunction.

Is supporting automodule discovery with nanobind something that would be considered for Sphinx? Are there any recommendations for how to get started with a PR for this, or perhaps where to focus efforts towards that?

How to Reproduce

This repository can be used for testing with sphinx, though does not have a conf.py set up: https://github.com/wjakob/nanobind_example

Environment Information

Please paste all output below into the bug report template



Platform:              linux; (Linux-4.18.0-553.56.1.el8_10.x86_64-x86_64-with-glibc2.28)
Python version:        3.13.3 | packaged by conda-forge | (main, Apr 14 2025, 20:44:03) [GCC 13.3.0])
Python implementation: CPython
Sphinx version:        8.3.0
Docutils version:      0.21.2
Jinja2 version:        3.1.6
Pygments version:      2.19.1

Sphinx extensions

sphinx.ext.autodoc

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions