pybind / pybind/pybind11

[BUG]: writes to std::array is not working

Open
#5,754 3 comments 0 reactions 0 assignees View on GitHub

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
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.