perhaps should not touch newly created tuple as object

This commit is contained in:
Taiju Yamada 2022-06-15 15:39:47 +09:00
parent bf238d91ed
commit c19ac6a55c
2 changed files with 9 additions and 6 deletions

View File

@ -138,12 +138,14 @@ TEST_SUBMODULE(pytypes, m) {
m.def("tuple_ssize_t", []() { return py::tuple{(py::ssize_t) 0}; });
m.def("tuple_size_t", []() { return py::tuple{(py::size_t) 0}; });
m.def("get_tuple", []() { return py::make_tuple(42, py::none(), "spam"); });
m.def("access_tuple_with_int_index", []() {
py::object tpl = py::make_tuple(1, 2);
m.def("access_tuple", [](py::tuple &tpl) {
return tpl[1];
});
m.def("access_tuple_with_int_index_multidimension", []() {
py::object tpl = py::make_tuple(py::make_tuple(1, 2, 3), py::make_tuple(3, 4, 5));
m.def("access_tuple_as_object_with_int_index", [](py::object &tpl) {
return tpl[1];
});
m.def("access_tuple_as_object_with_int_index_multidimension", [](py::object &tpl) {
return tpl[1][2];
});

View File

@ -155,8 +155,9 @@ def test_tuple():
assert m.tuple_ssize_t() == ()
assert m.tuple_size_t() == ()
assert m.get_tuple() == (42, None, "spam")
assert m.access_tuple_with_int_index() == 2
assert m.access_tuple_with_int_index_multidimension() == 5
assert m.access_tuple((1,2)) == 2
assert m.access_tuple_as_object_with_int_index((1,2)) == 2
assert m.access_tuple_as_object_with_int_index_multidimension(((1,2,3),(4,5,6))) == 6
def test_simple_namespace():