mirror of
https://github.com/pybind/pybind11.git
synced 2026-06-07 16:25:12 +00:00
type_caster<std::function>: allow None values in both directions
This commit is contained in:
@@ -38,7 +38,10 @@ py::cpp_function test_callback5() {
|
||||
int dummy_function(int i) { return i + 1; }
|
||||
int dummy_function2(int i, int j) { return i + j; }
|
||||
std::function<int(int)> roundtrip(std::function<int(int)> f) {
|
||||
std::cout << "roundtrip.." << std::endl;
|
||||
if (!f)
|
||||
std::cout << "roundtrip (got None).." << std::endl;
|
||||
else
|
||||
std::cout << "roundtrip.." << std::endl;
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,8 @@ from example import roundtrip
|
||||
|
||||
test_dummy_function(dummy_function)
|
||||
test_dummy_function(roundtrip(dummy_function))
|
||||
if roundtrip(None) is not None:
|
||||
print("Problem!")
|
||||
test_dummy_function(lambda x: x + 2)
|
||||
|
||||
try:
|
||||
|
||||
@@ -30,6 +30,7 @@ Copy constructions: 1
|
||||
Move constructions: True
|
||||
argument matches dummy_function
|
||||
eval(1) = 2
|
||||
roundtrip (got None)..
|
||||
roundtrip..
|
||||
argument matches dummy_function
|
||||
eval(1) = 2
|
||||
|
||||
Reference in New Issue
Block a user