[BUG]: writes to std::array is not working
Open
Nobody has claimed this yet.
triage
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
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.
What version (or hash if on master) of pybind11 are you using?
v3.0
Problem description
if an array is used in a struct as a member variable, writes from python are not registered
Reproducible example code
#include <array>
#include <pybind11/pybind11.h>
namespace py = pybind11;
struct foo {
foo() = default;
std::array<uint32_t, 2> bar;
};
PYBIND11_MODULE(my_module, m) {
py::class_<foo>(m, "foo")
.def(py::init<>())
.def_readwrite("bar", &foo::bar);
}
import my_module
foo = my_module.foo()
foo.bar[0] = 5
print(foo.bar[0])
Is this a regression? Put the last known working version here if it is.
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided C++ binding using std::array and the Python assignment example, then trace the def_readwrite path for array members. Reproduce the reported behavior and verify the fix by confirming that assigning foo.bar[0] from Python is reflected when it is read back.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100