Skip to content

Commit 011663d

Browse files
committed
enable new behavior only for Python 3, adjust new test to work with Python 2
1 parent 3d80ad5 commit 011663d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

include/pybind11/stl.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ template <typename Type, typename Value> struct list_caster {
144144
using value_conv = make_caster<Value>;
145145

146146
bool load(handle src, bool convert) {
147-
if (!isinstance<sequence>(src) || (!isinstance<bytes>(src) && isinstance<str>(src)))
147+
if (!isinstance<sequence>(src) || (
148+
#if PY_MAJOR_VERSION >= 3
149+
!isinstance<bytes>(src) &&
150+
#endif
151+
isinstance<str>(src)))
148152
return false;
149153
auto s = reinterpret_borrow<sequence>(src);
150154
value.clear();

tests/test_stl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def test_function_with_string_and_vector_string_arg():
247247

248248
def test_bytes_to_vector_uint8_t():
249249
"""Check if a bytes is implicitly converted to std::vector<uint8_t>, issue #1807"""
250-
assert m.func_with_vector_uint8_t_arg(b'abc') == 3
250+
assert m.func_with_vector_uint8_t_arg([ord(c) for c in b'abc']) == 3
251251
with pytest.raises(TypeError):
252252
m.func_with_vector_uint8_t_arg('stringval')
253253

0 commit comments

Comments
 (0)