Closed nurpax closed 2 months ago
Expected behavior: I don't expect the contents of nb::sig
s to add new imports to generated .pyi files.
The stub generator expects fully namespace-qualified type names. You must add the module name in front.
Did you add some flag to the stub generator that it should include private bits? I'm surprised that it shows enum
members like _member_names_
Did you add some flag to the stub generator that it should include private bits?
I have been wondering where and why these are coming from. Maybe it's because I use INCLUDE_PRIVATE
in my cmake config:
nanobind_add_stub(
slimgui_ext_stub
MODULE slimgui_ext
OUTPUT "${CMAKE_SOURCE_DIR}/src/slimgui/slimgui_ext.pyi"
PYTHON_PATH $<TARGET_FILE_DIR:slimgui_ext>
DEPENDS slimgui_ext
INCLUDE_PRIVATE
)
I use this option because ImGui includes enums that have a trailing underscore such as this INVALID_MASK_
below:
nb::enum_<ImGuiSliderFlags_>(m, "SliderFlags", nb::is_arithmetic())
.value("NONE", ImGuiSliderFlags_None)
.value("ALWAYS_CLAMP", ImGuiSliderFlags_AlwaysClamp)
.value("LOGARITHMIC", ImGuiSliderFlags_Logarithmic)
.value("NO_ROUND_TO_FORMAT", ImGuiSliderFlags_NoRoundToFormat)
.value("NO_INPUT", ImGuiSliderFlags_NoInput)
.value("INVALID_MASK_", ImGuiSliderFlags_InvalidMask_);
The stub generator expects fully namespace-qualified type names
OK, I'll try that! EDIT: it worked! Closing the bug.
Problem description
Python 3.11, Nanobind master from a few days ago.
I define a function binding like so:
nb::sig()
contentsMouseButton | int
and/or default argumentMouseButton.LEFT
cause the output stubs to include an import for MouseButton:If I define the API bindging as (without a reference to MouseButton):
the import disappears and the start of the generated stub looks like this:
MouseButton is an enum in my bindings and its stub looks like this:
Reproducible example code
python -m nanobind.stubgen -m nanobind_example.nanobind_example_ext -o out.pyi
Modified nanobind_example code:
The output stub looks like this: