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

Introduce def_visitor abstraction for objects that provide custom binding logic when passed to def() #884

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

oremanj
Copy link
Contributor

@oremanj oremanj commented Jan 27, 2025

This has two purposes:

  • I'm planning to contribute some class_ extensions (for pickling and buffer protocol support) that I would like to be able to put in their own headers so they don't slow down compilation for those that don't use them. This PR allows class_::def() to perform an operation that was not foreseen by the code inside class_.
  • I've found it quite ergonomically useful (and am carrying a local patch) to be able to add customizations by chaining .def(my_thing()) to a class binding, rather than the existing supported alternative of giving the binding a name and calling a helper function on it (auto someCls = nb::class_<...>(...); my_thing(someCls);).

Previously class_filler, renamed to def_visitor per feedback.

@wjakob
Copy link
Owner

wjakob commented Jan 28, 2025

This is great! I like def_visitor as name.

@oremanj oremanj changed the title Introduce class_filler abstraction for objects that provide custom binding logic when passed to def() Introduce def_visitor abstraction for objects that provide custom binding logic when passed to def() Jan 28, 2025
@oremanj
Copy link
Contributor Author

oremanj commented Jan 28, 2025

Great, renamed!

@wjakob wjakob merged commit 89c40e1 into wjakob:master Jan 28, 2025
31 checks passed
@wjakob
Copy link
Owner

wjakob commented Jan 28, 2025

Thanks!

@ManifoldFR
Copy link

Wow, thanks for adding this!!
This should make the transition for some of us who still use Boost.Python (and hadn't moved to Pybind11) much easier, since BP also had this def_visitor method-chaining pattern.

@oremanj oremanj deleted the class-filler branch February 7, 2025 00:33
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