File tree Expand file tree Collapse file tree 4 files changed +22
-1
lines changed Expand file tree Collapse file tree 4 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,9 @@ v2.3.0 (Not yet released)
47
47
* ``pybind11_add_module() ``: allow including Python as a ``SYSTEM `` include path.
48
48
`#1416 <https://github.com/pybind/pybind11/pull/1416 >`_.
49
49
50
+ * ``pybind11/stl.h `` does not convert strings to ``vector<string> `` anymore.
51
+ `#1258 <https://github.com/pybind/pybind11/issues/1258 >`_.
52
+
50
53
v2.2.4 (September 11, 2018)
51
54
-----------------------------------------------------
52
55
Original file line number Diff line number Diff line change @@ -138,7 +138,7 @@ template <typename Type, typename Value> struct list_caster {
138
138
using value_conv = make_caster<Value>;
139
139
140
140
bool load (handle src, bool convert) {
141
- if (!isinstance<sequence>(src))
141
+ if (!isinstance<sequence>(src) || isinstance<str>(src) )
142
142
return false ;
143
143
auto s = reinterpret_borrow<sequence>(src);
144
144
value.clear ();
Original file line number Diff line number Diff line change 11
11
#include " constructor_stats.h"
12
12
#include < pybind11/stl.h>
13
13
14
+ #include < vector>
15
+ #include < string>
16
+
14
17
// Test with `std::variant` in C++17 mode, or with `boost::variant` in C++11/14
15
18
#if PYBIND11_HAS_VARIANT
16
19
using std::variant;
@@ -33,6 +36,8 @@ struct visit_helper<boost::variant> {
33
36
}} // namespace pybind11::detail
34
37
#endif
35
38
39
+ PYBIND11_MAKE_OPAQUE (std::vector<std::string, std::allocator<std::string>>);
40
+
36
41
// / Issue #528: templated constructor
37
42
struct TplCtorClass {
38
43
template <typename T> TplCtorClass (const T &) { }
@@ -237,6 +242,11 @@ TEST_SUBMODULE(stl, m) {
237
242
// test_stl_pass_by_pointer
238
243
m.def (" stl_pass_by_pointer" , [](std::vector<int >* v) { return *v; }, " v" _a=nullptr );
239
244
245
+ // #1258: pybind11/stl.h converts string to vector<string>
246
+ m.def (" func_with_string_or_vector_string_arg_overload" , [](std::vector<std::string>) { return 1 ; });
247
+ m.def (" func_with_string_or_vector_string_arg_overload" , [](std::list<std::string>) { return 2 ; });
248
+ m.def (" func_with_string_or_vector_string_arg_overload" , [](std::string) { return 3 ; });
249
+
240
250
class Placeholder {
241
251
public:
242
252
Placeholder () { print_created (this ); }
Original file line number Diff line number Diff line change @@ -201,6 +201,14 @@ def test_missing_header_message():
201
201
assert expected_message in str (excinfo .value )
202
202
203
203
204
+ def test_function_with_string_and_vector_string_arg ():
205
+ """Check if a string is NOT implicitly converted to a list, which was the
206
+ behavior before fix of issue #1258"""
207
+ assert m .func_with_string_or_vector_string_arg_overload (('A' , 'B' , )) == 2
208
+ assert m .func_with_string_or_vector_string_arg_overload (['A' , 'B' ]) == 2
209
+ assert m .func_with_string_or_vector_string_arg_overload ('A' ) == 3
210
+
211
+
204
212
def test_stl_ownership ():
205
213
cstats = ConstructorStats .get (m .Placeholder )
206
214
assert cstats .alive () == 0
You can’t perform that action at this time.
0 commit comments