You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to get functional singleton but I am not able to get it working quite the way I wish. The singleton behaviour work actually, so importing the class Undefined in the python code and assert Undefined() == Undefined() works fine.
However, I want to be able to do:
fromximportUndefinedassertUndefined==Undefined# no parenthesisassertrepr(Undefined) =="Undefined"# This is now <capsule object at 0x...>
PYBIND11_MODULE(x, m)
// Ideally here I would like to do// m.attr("Undefined", Undefined::instance());
py::class_<Undefined>(m, "Undefined") // FIXME: wouldn't want to define this here.
.def_static("__new__", [](const py::object &) {
returnUndefined::instance(); })
.def(py::init<>([](const Undefined& self) { return self; }))
.def("__repr__", [](py::handle self) { returnpy::str("<Undefined>"); }); // THIS DOES NOT SEEM TO WORK?!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
I am trying to get functional singleton but I am not able to get it working quite the way I wish. The singleton behaviour work actually, so importing the class
Undefined
in the python code andassert Undefined() == Undefined()
works fine.However, I want to be able to do:
Can anyone help with this, please?
Below is the c++ code.
Binding
Beta Was this translation helpful? Give feedback.
All reactions