Skip to content

Conversation

@oremanj
Copy link
Contributor

@oremanj oremanj commented Jan 28, 2025

Unlike the corresponding pybind11 feature, the lambda must return by value, not by pointer. This simplifies the plumbing quite a bit and allows us to typically take advantage of guaranteed copy elision, producing basically the same code that we would have gotten from the previously-recommended manual __init__ approach. Manual __init__ is still the most appropriate method if some action needs to be taken after calling the C++ constructor.

This PR fully supports alias/trampoline classes, including the option to pass separate factory functions for constructing the bound type vs the trampoline type, except that I didn't bother providing an equivalent of pybind11's init_alias for forcing to always construct the trampoline type (since we don't have that for C++-provided constructors either). If this PR is judged too complex, the easiest way to simplify it would be by dropping support for trampoline classes. I'm a bit reluctant to do that though, since there is no supported API for constructing a trampoline class using the manual approach (since detail::nb_inst_python_derived() is internal).

@wjakob wjakob force-pushed the master branch 4 times, most recently from 9063be4 to 61e044d Compare April 11, 2025 06:20
@wjakob wjakob force-pushed the master branch 3 times, most recently from 4d71d9a to 238b695 Compare October 27, 2025 19:38
@wjakob wjakob force-pushed the master branch 4 times, most recently from 477f67b to 75f7046 Compare December 8, 2025 14:57
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.

1 participant