functional: support bound methods

If a bound std::function is invoked with a bound method, the implicit
bound self is lost because we use `detail::get_function` to unbox the
function.  This commit amends the code to use py::function and only
unboxes in the special is-really-a-c-function case.  This makes bound
methods stay bound rather than unbinding them by forcing extraction of
the c function.
This commit is contained in:
Jason Rhinelander
2017-04-24 12:29:42 -04:00
parent 7653a115bd
commit a01b6b805c
4 changed files with 35 additions and 11 deletions

View File

@@ -27,6 +27,21 @@ def test_callbacks():
assert f(number=43) == 44
def test_bound_method_callback():
from pybind11_tests import test_callback3, CppBoundMethodTest
# Bound Python method:
class MyClass:
def double(self, val):
return 2 * val
z = MyClass()
assert test_callback3(z.double) == "func(43) = 86"
z = CppBoundMethodTest()
assert test_callback3(z.triple) == "func(43) = 129"
def test_keyword_args_and_generalized_unpacking():
from pybind11_tests import (test_tuple_unpacking, test_dict_unpacking, test_keyword_args,
test_unpacking_and_keywords1, test_unpacking_and_keywords2,