You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
AFAICT, the int typedefs for enums are to make it handier to deal with bit flags in C++. Alas, this reduces type precision in how flag fields are typed in bindings.
In my binding code, I'm generating IntEnums for the various Flags fields, which end up looking something like this:
class InputTextFlags(enum.IntEnum):
NONE: InputTextFlags
CHARS_DECIMAL: InputTextFlags
CHARS_HEXADECIMAL: InputTextFlags
I bind the ImGui::InputText function with code like this:
But what I'd actually like to output would be something like below (flags is typed InputTextFlags|int):
# Accept both an InputTextFlags or an int. The intent here is to make typings
# more self-documenting.
def input_text(label: str, text: str, flags: InputTextFlags | int = InputTextFlags.NONE) -> tuple[bool, str]: ...
However, it looks like the only way to generate the above typings is the declare a sig for the whole function:
It almost feels like bit of an oversight that .sig() only controls the default value, not the whole arg type. Even the docs for the function level nb::sig() seem to suggest this:
In cases where a custom signature is only needed to tweak how nanobind renders the signature of a default argument, the more targeted nb::arg("name").sig("signature") annotation is preferable to nb::sig.
I wonder if I'm missing an option in the library to control how args get rendered?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Sorry for the lengthy post. I'm trying to include enough code to communicate intent in more concrete terms.
I'm working on imgui bindings where many functions have a
flags
argument that's basically anint
but is declared like this:AFAICT, the int typedefs for enums are to make it handier to deal with bit flags in C++. Alas, this reduces type precision in how flag fields are typed in bindings.
In my binding code, I'm generating IntEnums for the various Flags fields, which end up looking something like this:
I bind the ImGui::InputText function with code like this:
Which renders the following typing (
flags
is typedint
):But what I'd actually like to output would be something like below (
flags
is typedInputTextFlags|int
):However, it looks like the only way to generate the above typings is the declare a sig for the whole function:
This would mean I'd have to manually write function typings for a large number of API entries.
Instead, I'd like to be able to overide just the signature part for the
flags
argument with something like this:It almost feels like bit of an oversight that
.sig()
only controls the default value, not the whole arg type. Even the docs for the function levelnb::sig()
seem to suggest this:I wonder if I'm missing an option in the library to control how args get rendered?
Beta Was this translation helpful? Give feedback.
All reactions