diff --git a/include/pybind11/stl.h b/include/pybind11/stl.h index 721bb669f0..2ff65b16a4 100644 --- a/include/pybind11/stl.h +++ b/include/pybind11/stl.h @@ -144,7 +144,15 @@ template struct list_caster { using value_conv = make_caster; bool load(handle src, bool convert) { +#if 1 if (!isinstance(src) || isinstance(src)) +#else + if (!isinstance(src) || ( +#if PY_MAJOR_VERSION >= 3 + !isinstance(src) && +#endif + isinstance(src))) +#endif return false; auto s = reinterpret_borrow(src); value.clear(); diff --git a/tests/test_stl.cpp b/tests/test_stl.cpp index 0590162770..14ecd35ee4 100644 --- a/tests/test_stl.cpp +++ b/tests/test_stl.cpp @@ -291,6 +291,9 @@ TEST_SUBMODULE(stl, m) { m.def("func_with_string_or_vector_string_arg_overload", [](std::list) { return 2; }); m.def("func_with_string_or_vector_string_arg_overload", [](std::string) { return 3; }); + // #1807: 2.3.0 regression: is not converted to std::vector anymore + //m.def("func_with_vector_uint8_t_arg", [](std::vector v) { return v.size(); }); + class Placeholder { public: Placeholder() { print_created(this); } diff --git a/tests/test_stl.py b/tests/test_stl.py index 330017544d..ff6f910d69 100644 --- a/tests/test_stl.py +++ b/tests/test_stl.py @@ -245,6 +245,13 @@ def test_function_with_string_and_vector_string_arg(): assert m.func_with_string_or_vector_string_arg_overload("A") == 3 +#def test_bytes_to_vector_uint8_t(): +# """Check if a bytes is implicitly converted to std::vector, issue #1807""" +# assert m.func_with_vector_uint8_t_arg([ord(c) for c in b'abc']) == 3 +# with pytest.raises(TypeError): +# m.func_with_vector_uint8_t_arg('stringval') + + def test_stl_ownership(): cstats = ConstructorStats.get(m.Placeholder) assert cstats.alive() == 0