Open jjcasmar opened 3 years ago
Works fine for me. You'll have to give more context and provide a minimal example.
#include <pybind11/pybind11.h>
enum class E { a, b };
struct s {
E e;
auto get() const { return e; }
auto set(E e_) { e = e_; }
};
PYBIND11_MODULE(foo, m) {
pybind11::enum_<E>(m, "E").value("a", E::a).value("b", E::b);
pybind11::class_<s>(m, "s").def_property("e", &s::get, &s::set).def(pybind11::init<>());
}
>>> import foo
>>> f=foo.s()
>>> f
<foo.s object at 0x7f0d2aa465b0>
>>> f.e
<E.a: 0>
>>> f.e=foo.E.b
>>> f.e
<E.b: 1>
I am trying to export an enum and a property for a class which uses the enum. In my class I have this two methods
the enum is defined in the scope of my class
I create bindings for both the enum and the class like this
The getter works fine. I am able to read the property from python and when debugging, it stop in a breakpoint inside the getter. However, the setter doesn't work, it is never called.
From python, I can do the following:
However, it works fine if I change to a readonly property + a function which sets the value (.def_property_readonly + .def)