Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

functional: support bound methods #815

Merged
merged 1 commit into from
Apr 29, 2017

Conversation

jagerman
Copy link
Member

If a bound std::function is invoked with a bound method, the implicit bound self is lost; the method is called with the first argument as self. This commits adds bound method detection and re-adds the
implicit self into the call arguments for bound methods.

Fixes #814.

@wjakob
Copy link
Member

wjakob commented Apr 28, 2017

Interesting -- this case had never occurred to me. Would it be easier to simply not unbox the method in detail::get_function?

@jagerman
Copy link
Member Author

It looks like other code expects unboxing: removing it causes various other tests to fail with maximum recursion errors.

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.
@jagerman
Copy link
Member Author

I cleaned it up a bit to go through py::function, which doesn't unbox, but supports explicit unboxing (for the special really-a-C++-function bypass case).

@wjakob
Copy link
Member

wjakob commented Apr 28, 2017

LGTM!

@dean0x7d
Copy link
Member

Looks good to me!

This also reminded me that else if is just else + if. I had a mental compiler error for a second :)

@jagerman jagerman merged commit a01b6b8 into pybind:master Apr 29, 2017
@dean0x7d dean0x7d modified the milestone: v2.2 Aug 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants