Replies: 1 comment 8 replies
-
No, that is the way to go. You should be able to avoid the first call using something like (untested) using Caster = nanobind::detail::make_caster<T>;
if constexpr (nanobind::detail::is_base_caster_v<Caster>)
// case A
else
// case B |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to customize signatures programatically, which requires a reliable way of getting python types from C++ types.
The low-level interface docs suggest for this use case to use
nb::type<MyType>
, which works for bound types. However, this doesn't show types that are converted by type casters. If I usemake_caster<MyType>::Name
, that doesn't show bound types. Right now I'm trying one and falling back on the other, and that seems to work, but it seems brittle.From reading the source code, it seems that the true type signature is actually made in
nb_func_render_signature
. Does that mean that the canonical way to get the python type from C++ type is to create a function (perhaps withcpp_function
on a throwaway lambda), and then get its signature withgetattr
/__nb_signature__
and then parse it? That would make sense, since C++ types can have different python types depending on if it's an argument or return value, etc.Is this the simplest way to canonically get a python type string from a C++ type? Something like:
Is there a reason not to expose such functionality as part of the API?
edit - for reference, my current method is something like:
Beta Was this translation helpful? Give feedback.
All reactions