Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
011663df
Commit
011663df
authored
Dec 03, 2020
by
Ralf W. Grosse-Kunstleve
Browse files
enable new behavior only for Python 3, adjust new test to work with Python 2
parent
3d80ad57
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
2 deletions
+6
-2
include/pybind11/stl.h
include/pybind11/stl.h
+5
-1
tests/test_stl.py
tests/test_stl.py
+1
-1
No files found.
include/pybind11/stl.h
View file @
011663df
...
@@ -144,7 +144,11 @@ template <typename Type, typename Value> struct list_caster {
...
@@ -144,7 +144,11 @@ template <typename Type, typename Value> struct list_caster {
using
value_conv
=
make_caster
<
Value
>
;
using
value_conv
=
make_caster
<
Value
>
;
bool
load
(
handle
src
,
bool
convert
)
{
bool
load
(
handle
src
,
bool
convert
)
{
if
(
!
isinstance
<
sequence
>
(
src
)
||
(
!
isinstance
<
bytes
>
(
src
)
&&
isinstance
<
str
>
(
src
)))
if
(
!
isinstance
<
sequence
>
(
src
)
||
(
#if PY_MAJOR_VERSION >= 3
!
isinstance
<
bytes
>
(
src
)
&&
#endif
isinstance
<
str
>
(
src
)))
return
false
;
return
false
;
auto
s
=
reinterpret_borrow
<
sequence
>
(
src
);
auto
s
=
reinterpret_borrow
<
sequence
>
(
src
);
value
.
clear
();
value
.
clear
();
...
...
tests/test_stl.py
View file @
011663df
...
@@ -247,7 +247,7 @@ def test_function_with_string_and_vector_string_arg():
...
@@ -247,7 +247,7 @@ def test_function_with_string_and_vector_string_arg():
def
test_bytes_to_vector_uint8_t
():
def
test_bytes_to_vector_uint8_t
():
"""Check if a bytes is implicitly converted to std::vector<uint8_t>, issue #1807"""
"""Check if a bytes is implicitly converted to std::vector<uint8_t>, issue #1807"""
assert
m
.
func_with_vector_uint8_t_arg
(
b
'abc'
)
==
3
assert
m
.
func_with_vector_uint8_t_arg
(
[
ord
(
c
)
for
c
in
b
'abc'
]
)
==
3
with
pytest
.
raises
(
TypeError
):
with
pytest
.
raises
(
TypeError
):
m
.
func_with_vector_uint8_t_arg
(
'stringval'
)
m
.
func_with_vector_uint8_t_arg
(
'stringval'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment