-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to expose custom type derived from pure python type #1170
Comments
Inheriting directly from Python classes like that isn't feasible: method availability isn't determined until runtime in Python, but needs to be known during compilation in C++. What you'll need to do instead is write a C++ class that provides the methods you want and maps these into Python function calls. So, for example, this class could store a |
Thanks for the clarification, |
Is there a way to write a short Python "bridge" so that |
Have a look at For example, I've recently found out that while |
Awesome thanks! |
I believe I may have ran into a situation where I now need this to: I am tinkering with making a In looking at the NumPy example code, it looks like the object has to inherit from My current thoughts on working around this are to (a) write a wrapper / shim class - blech - or (b) just avoid trying to shove |
If you can easily extend both classes in your python code, I'd strongly suggest doing that. The bindings can't extend anything they are not aware of at build time. |
Thanks! Unfortunately, it was rather painful (or rather, confusing) to try and make a separate In the end, I just ended up abusing |
Issue description
My goal is to create a wrapper to the python default
file
type.For that I created a C++ class (with no base class) and I want to expose it as a subclass of
file
. Which I cannot do asfile
isn't itself exported by pybind11.Is there a way to support this pattern with this library (I couldn't find this workflow in the doc) ?
The text was updated successfully, but these errors were encountered: