Skip to content

Is there some way to create proxy for pybind11-exported class ? #3411

Answered by edimetia3d
edimetia3d asked this question in Q&A
Discussion options

You must be logged in to vote

Here, we had found a solution.

I want to first show what we had achieved.

Given the _zoo is a simple pybind11 module that has Animal and Dog class.

We created two proxy classes at python side, which will hold their own wrapped object by using the has-a logical, not is-a.

These proxy classes will follow the Proxy pattern, they could be used in any pybind11 exported function that requires an raw object.

And more, any pybind11 exported function will return the proxy object instead of raw object.

By using this, we could completely hide the pybind11-exported types, and extend these pybind11-exported types with pure python code in a more structural way.

import _zoo


def real_type(RealT):
    def 

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@jiwaszki
Comment options

@edimetia3d
Comment options

Comment options

You must be logged in to vote
1 reply
@edimetia3d
Comment options

Answer selected by edimetia3d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants