Skip to content

[BUG]: __getattr__ and smart_holders #3788

Description

@petersteneteg

Required prerequisites

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; });
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

triageNew bug, unverified

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions