Closed
Description
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
Problem description
This is a problem in the smart_holder
branch
When defining __getattr__
in the bindings for a class (see example code below) using the master
pybind11 branch I can do the following:
In [1]: import foo
In [2]: f = foo.Foo()
In [3]: f.bar()
Out[3]: 42
In [5]: f.something
Out[5]: 'GetAttr: something'
and everything works as expected.
But when using the smart_holder
branch and defining PYBIND11_USE_SMART_HOLDER_AS_DEFAULT
either calling f.bar()
or f.something
results in infinite recursion, hanging the runtime. Using "conservative mode" gives the same result.
Im not sure if I'm doing anything bad, and I can not find anything about it not being supported it in the documentation, and it works perfectly fine in the master
branch.
Reproducible example code
#include <pybind11/pybind11.h>
struct Foo {
Foo() = default;
int bar() const { return 42; }
};
namespace py = pybind11;
PYBIND11_MODULE(foo, m) {
py::class_<Foo>(m, "Foo")
.def(py::init<>())
.def("bar", &Foo::bar)
.def("__getattr__", [](Foo&, std::string key) { return "GetAttr: " + key; });
}