mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-21 20:55:11 +00:00
std::array<> caster: support arbitrary sequences (#1602)
This PR brings the std::array<> caster in sync with the other STL type casters: to accept an arbitrary sequence as input (rather than a list, which is too restrictive).
This commit is contained in:
parent
978d439e92
commit
9f73060cc7
@ -199,9 +199,9 @@ private:
|
||||
|
||||
public:
|
||||
bool load(handle src, bool convert) {
|
||||
if (!isinstance<list>(src))
|
||||
if (!isinstance<sequence>(src))
|
||||
return false;
|
||||
auto l = reinterpret_borrow<list>(src);
|
||||
auto l = reinterpret_borrow<sequence>(src);
|
||||
if (!require_size(l.size()))
|
||||
return false;
|
||||
size_t ctr = 0;
|
||||
|
@ -263,4 +263,6 @@ TEST_SUBMODULE(stl, m) {
|
||||
return result;
|
||||
},
|
||||
py::return_value_policy::take_ownership);
|
||||
|
||||
m.def("array_cast_sequence", [](std::array<int, 3> x) { return x; });
|
||||
}
|
||||
|
@ -216,3 +216,7 @@ def test_stl_ownership():
|
||||
assert len(r) == 1
|
||||
del r
|
||||
assert cstats.alive() == 0
|
||||
|
||||
|
||||
def test_array_cast_sequence():
|
||||
assert m.array_cast_sequence((1, 2, 3)) == [1, 2, 3]
|
||||
|
Loading…
Reference in New Issue
Block a user