Generate documentation and stub file for nanobind Python module #171
yosh-matsuda
started this conversation in
Ideas
Replies: 1 comment 3 replies
-
Regarding I am open to removing the |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've been trying to use a Python module built with nanobind to automatically generate documentation and stub files. My goal is to achieve this using Sphinx and mypy-stubgen. This has now been almost achieved for my use case with my own small fixes:
Here, I would like to share what nanobind can do to make them possible without such modifications in my observations. If the following problems are solved, Sphinx and mypy-stubgen would work almost perfectly I think.
1.
nanobind.nb_func
The nanobind bound functions are not recognized as Python functions (
inspect.isfunction
) because the type of the boud functions seems to benanobind.nb_func
defined innb_internal.h
. My question is, is it possible to make the boud function as if it is built-in like pybind11? I don't know how to deal with this as my understanding of nanobind internals and cpython is limited.2. Incompatible type hints
I've noticed that the stubgen cannot recognize type names in some cases. Can I ask if there is anything we should fix in nanobind?
<anonymous>(...) -> ...
, on the other hand, it supports pybind11-style anonymous type hints like(...) -> ...
implemented in Improve stubgenc type detection on PyBind11 properties python/mypy#8995. The nanobind may not need<anonymous>
in the docstring if compatibility with pybind11 is important, otherwise, I'm afraid that this should be handled on the mypy side.numpy.ndarray[dtype=float32, shape=(2, 4)]
) cannot be parsed as type in the stubgen. This is probably due to the= ( )
characters, which are not normally used in type names. I have changed the ndarray type name generation inndarray.h
and confirmed thatnumpy.ndarray[dtype[float32], shape[2, 4]]
works well for example.Beta Was this translation helpful? Give feedback.
All reactions