Skip to content

Pybind11: typedef and incompatible function arguments error #5237

Answered by jiwaszki
xliuk asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @xliuk , one way to make it work is to make types opaque. The thing is that you are using typedef of std::tuple, which during compilation substitutes both Type and Shape to tuple -- thus you can see Tuple[...] in signature of the init.
What you need to add on top of your bindings:

typedef std::tuple<int, int, int> Type;
typedef std::tuple<int, int, int, int> Shape;

PYBIND11_MAKE_OPAQUE(Type);
PYBIND11_MAKE_OPAQUE(Shape);
In [1]: import mymodule
   ...: 
   ...: type = mymodule.Type(0,8,1)
   ...: shape = mymodule.Shape(10,10,10,10)
   ...: prop = mymodule.Properties(type, shape)
   ...: 
   ...: print(prop.type, prop.shape)
(0, 8, 1) (10, 10, 10, 10)

Here is more info on it: https://p…

Replies: 1 comment 1 reply

Comment options

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

Answer selected by xliuk
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