mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-19 14:29:11 +00:00
relax operator[] for tuples, lists, and sequences
object_api::operator[] has a powerful overload for py::handle that can accept slices, tuples (for NumPy), etc. Lists, sequences, and tuples provide their own specialized operator[], which unfortunately disables this functionality. This is accidental, and the purpose of this commit is to re-enable the more general behavior. This commit is tangentially related to the previous one in that it makes py::handle/py::object et al. behave more like their Python counterparts.
This commit is contained in:
@@ -289,4 +289,8 @@ TEST_SUBMODULE(pytypes, m) {
|
||||
l.append(a << b);
|
||||
return l;
|
||||
});
|
||||
|
||||
m.def("test_list_slicing", [](py::list a) {
|
||||
return a[py::slice(0, -1, 2)];
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user