Merge pull request #135 from bennybp/master
Check for other callable python objects
diff --git a/example/example5.py b/example/example5.py
index 0699978..ef90cfd 100755
--- a/example/example5.py
+++ b/example/example5.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python
from __future__ import print_function
+from functools import partial
import sys
sys.path.append('.')
@@ -37,8 +38,13 @@
print('Callback function 2 called : ' + str(a) + ", " + str(b) + ", " + str(c) + ", "+ str(d))
return d
+def func3(a):
+ print('Callback function 3 called : ' + str(a))
+
print(test_callback1(func1))
print(test_callback2(func2))
+print(test_callback1(partial(func2, "Hello", "from", "partial", "object")))
+print(test_callback1(partial(func3, "Partial object with one argument")))
test_callback3(lambda i: i + 1)
f = test_callback4()
diff --git a/example/example5.ref b/example/example5.ref
index d1da883..bfc3cb2 100644
--- a/example/example5.ref
+++ b/example/example5.ref
@@ -19,4 +19,8 @@
False
Callback function 2 called : Hello, x, True, 5
5
+Callback function 2 called : Hello, from, partial, object
+False
+Callback function 3 called : Partial object with one argument
+False
func(43) = 44
diff --git a/include/pybind11/functional.h b/include/pybind11/functional.h
index 95ac7c9..f00a603 100644
--- a/include/pybind11/functional.h
+++ b/include/pybind11/functional.h
@@ -20,7 +20,7 @@
public:
bool load(handle src_, bool) {
src_ = detail::get_function(src_);
- if (!src_ || !(PyFunction_Check(src_.ptr()) || PyCFunction_Check(src_.ptr())))
+ if (!src_ || !PyCallable_Check(src_.ptr()))
return false;
object src(src_, true);
value = [src](Args... args) -> Return {
diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h
index dd86bbb..8e5cdc6 100644
--- a/include/pybind11/pytypes.h
+++ b/include/pybind11/pytypes.h
@@ -428,7 +428,7 @@
class function : public object {
public:
- PYBIND11_OBJECT_DEFAULT(function, object, PyFunction_Check)
+ PYBIND11_OBJECT_DEFAULT(function, object, PyCallable_Check)
bool is_cpp_function() const {
handle fun = detail::get_function(m_ptr);
return fun && PyCFunction_Check(fun.ptr());