Bound types with __instancecheck__
/__subclasscheck__
#1062
Unanswered
bethebunny
asked this question in
Q&A
Replies: 1 comment
-
nanobind does not permit metaclass customization. This is intentional and has come up a few times before (please see the issue/PR/discussion history). Based on your questions (also in separate threads), I think that you require a level of customization that will not be possible with stock nanobind, and you might consider to maintain your own fork. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a number of types that are implementing essentially an interface for other bound types. The C++ code knows which types "implement" those interfaces, so I can easily bind a function which typechecks them.
I'd like to use a normal pattern to compare these in python, eg.
if isinstance(o, MyInterface):
, which would also hint to the type checker thato
is a legalMyInterface
for usage. However,__instancecheck__
must be defined on the metaclass in Python.I don't think there's any easy way to actually implement this in nanobind today. I'm wondering if there's something tricky I can try with
nb::type_slots
, or if anyone has any other good ideas.Beta Was this translation helpful? Give feedback.
All reactions