Skip to content

Commit 2ed6208

Browse files
modify to show default args
1 parent 9c9b1f5 commit 2ed6208

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

tests/test_pytypes.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,13 @@ TEST_SUBMODULE(pytypes, m) {
319319
return a[py::slice(0, -1, 2)];
320320
});
321321

322-
m.def("test_str_with_cpp_default_none", []() {
323-
auto my_func = [](py::str value = py::none()) {
324-
return value;
325-
};
326-
return py::make_tuple(my_func(), my_func("Hello"));
322+
// See #2361
323+
m.def("test_str_with_default_arg_none" ,[](py::str value) {
324+
return value;
325+
}, py::arg("value") = py::none());
326+
m.def("test_str_assign_none", []() {
327+
py::str is_this_none = py::none();
328+
return is_this_none;
327329
});
328330

329331
m.def("test_memoryview_object", [](py::buffer b) {

tests/test_pytypes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,9 @@ def test_list_slicing():
281281
assert li[::2] == m.test_list_slicing(li)
282282

283283

284-
def test_str_with_cpp_default_none():
285-
assert m.test_str_with_cpp_default_none() == (None, "Hello")
284+
def test_str_with_none():
285+
assert m.test_str_assign_none() is None
286+
assert m.test_str_with_default_arg_none() is None
286287

287288

288289
@pytest.mark.parametrize('method, args, fmt, expected_view', [

0 commit comments

Comments
 (0)