RosettaCommons / binder

Binder, tool for automatic generation of Python bindings
MIT License
322 stars 66 forks source link

Binding __match_args__ #244

Closed nimski closed 2 years ago

nimski commented 2 years ago

I'll preface this by saying that Binder is awesome and I appreciate all the effort that's gone into it!

I'm wondering what the best way of binding the __match_args__ attribute is? It's used for case matching in Python and I think would best be represented in C++ as a static class variable:

class A {
static const std::vector __match_args__ = {"var1", "var2"};
public:
int var1;
int var2;
}

This would then ideally result in the Python interface:

class A:
    __match_args__ = ('var1', 'var2')

  ...

Is there a way to make this happen with Binder? If not supported currently, would you have pointers on how to go about modifying it to do something like this?

lyskov commented 2 years ago

@nimski i am not sure if special handling is needed is this case, - have you tried to simply add static __match_args__ (as in your example) to C++ class? - it should have worked as intended...

nimski commented 2 years ago

Thanks for your response. Unfortunately it looks like static class variables are ignored (no bindings generated). I think the only way to do this is to use an add_on_binding.

lyskov commented 2 years ago

Oh, i see... - i just pushed the patch thats enable binding generation for class const data members. Here is the example for generating __match_args__ annotation: https://github.com/RosettaCommons/binder/blob/master/test/T07.class.match_args.hpp#L17 - will something like this works for you? If so could you please give it try when you have a minute and let me know how it goes? Thanks,

nimski commented 2 years ago

Hi @lyskov , I'm sorry for the delay here. This is still on my radar and will let you know as soon as I've had a chance to try it.