type_caster_generic: add set_foreign_holder method for subclasses to implement (#5862)

* type_caster_generic: add set_foreign_holder method for subclasses to implement

* style: pre-commit fixes

* Rename try_shared_from_this -> set_via_shared_from_this to avoid confusion against try_get_shared_from_this

* Add comment explaining the limits of the test

* CI

* style: pre-commit fixes

* Fixes from code review

* style: pre-commit fixes

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Joshua Oreman
2025-10-13 20:00:28 -04:00
committed by GitHub
parent 9f75202191
commit c7b4f66a73
10 changed files with 186 additions and 16 deletions

View File

@@ -26,7 +26,9 @@ PYBIND11_MODULE(pybind11_cross_module_tests, m, py::mod_gil_not_used()) {
// test_load_external
bind_local<ExternalType1>(m, "ExternalType1", py::module_local());
bind_local<ExternalType2>(m, "ExternalType2", py::module_local());
bind_local<ExternalType2, 0, std::shared_ptr<ExternalType2>>(
m, "ExternalType2", py::module_local());
bind_local<ExternalType3, 0, py::smart_holder>(m, "ExternalType3", py::module_local());
// test_exceptions.py
py::register_local_exception<LocalSimpleException>(m, "LocalSimpleException");