nanobind-stubgen - Generate python stub files for code completion #163
Replies: 7 comments 9 replies
-
Have you tried mypy's subgen? |
Beta Was this translation helpful? Give feedback.
-
A few suggestions for the generated stubs:
Also, if you found a way to include the proper imports, that would be great... |
Beta Was this translation helpful? Give feedback.
-
Dear @cansik, thank you for building this, it looks great! I had actually planned to work on an stub generator for nanobind as well, but you beat me to it. This actually leads me to a somewhat awkward question: Would you be willing to co-maintain this software (and share admin privileges on GitHub+PyPI)? Alternatively (if you prefer to be in charge), would you mind giving your project a different name? The reason for this request is that I had planned to call my tool Features on my TODO list would be the ability to customize the stub generation. Some of my projects need specialized transformations on top of the initial output, so it should be possible to import the stub generator from Python and add callback hooks that modify class/function signatures. Thanks, |
Beta Was this translation helpful? Give feedback.
-
Thanks for this work! I am wondering what is the recommended way of integrating stub generation with the build process (e.g. with scikit-build as in nanobind_example). Specifically, I would love to auto-generated stub files and add it to the package when I |
Beta Was this translation helpful? Give feedback.
-
Piggy backing on this to propose that stub generation should be an included option that is integrated directly into nanobind (or pybind11). I want CMake to build my library and build bindings that are actually parseable by vscode/pylance or other security minded tools, instead of jumping through a thousand hoops to get basic linting and autocompletion working. Right now I have to have the user pip install the generator, then have CMake run a python script that tricks pybind11-stubgen into thinking its current python environment is in the build directory before running it. I also have to hardcode my enum class locations into the command, for whatever reason. |
Beta Was this translation helpful? Give feedback.
-
I think the approach used by nanobind-stubgen is flawed because the doc string signatures aren't always valid Python code (e.g. when default values have a I see a few approaches that would be more reliable:
|
Beta Was this translation helpful? Give feedback.
-
I created a tracking issue #420 to discuss a potential builtin mechanism for stub generation in a future version of nanobind. |
Beta Was this translation helpful? Give feedback.
-
Since python development with nanogui was difficult due to missing type information, I have written a simple (and basic) tool to create
.pyi
files for nanobind modules: nanobind-stubgen.The tool uses the
__doc__
string ofnb_*
objects to infer the correct types and works with already compiled modules. For example to generate nanogui bindings, use the following lines of code:The generate files can now be found in the
./nanogui
directory.Related to: #60 & mitsuba-renderer/nanogui#79
Beta Was this translation helpful? Give feedback.
All reactions