Skip to content

returning Python list of wrapped non-copyable type #1766

Closed
@Xeverous

Description

@Xeverous

Issue description

Returning a list of non copyable type raises an exception. This should not happen.

Reproducible example code

#include <pybind11/pybind11.h>

struct non_copyable
{
        non_copyable() = default;

        non_copyable(const non_copyable&) = delete;
        non_copyable& operator=(non_copyable) = delete;
        non_copyable(non_copyable&&) = default;
        non_copyable& operator=(non_copyable&&) = default;
};

PYBIND11_MODULE(test_mod, m)
{
        py::class_<non_copyable>(m, "NonCopyable")
                .def(py::init());
        m.def("get_list", []()
        {
                py::list list;
                list.append(non_copyable());
                list.append(non_copyable());
                return list;
        });
}
import test_mod

l = test_mod.get_list()
RuntimeError: return_value_policy = copy, but the object is non-copyable!

How can I return a list of objects that are not copyable? This looks like a bug to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions