pybind / pybind/pybind11

`py::list` iterator not assignable

Open
#996 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

This does not compile on GCC 5.4:

py::list out(1);
auto it = out.begin();
*it = py::cast(0);         // fails to compile

These other statements are OK:

out[0] = py::cast(0);      // works OK
out.append(py::cast(0));   // works OK

The error message indicates that *it is const. I guess it's related to this:

using list_iterator = generic_iterator<iterator_policies::sequence_fast_readonly>;

To me this is a bug, either in the documentation or in the code. Is there a specific reason for these iterators to be read-only? Am I supposed to create lists by appending elements one by one?

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

Reproduce the GCC 5.4 example and inspect the py::list iterator policy named in the issue, especially sequence_fast_readonly and generic_iterator. Determine whether iterator assignment is intended to be supported; done means either the sample compiles with the intended mutable behavior or the documentation clearly explains why these iterators are read-only.

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.