| 163 | } |
| 164 | |
| 165 | inline PyObject *reduce_ex_impl(PyObject *self, PyObject *, PyObject *) { |
| 166 | // Deliberately ignoring the arguments for simplicity (expected is `protocol: int`). |
| 167 | const function_record *rec = function_record_ptr_from_PyObject(self); |
| 168 | if (rec == nullptr) { |
| 169 | pybind11_fail( |
| 170 | "FATAL: function_record_PyTypeObject reduce_ex_impl(): cannot obtain cpp_func_rec."); |
| 171 | } |
| 172 | if (rec->name != nullptr && rec->name[0] != '\0' && rec->scope |
| 173 | && PyModule_Check(rec->scope.ptr()) != 0) { |
| 174 | object scope_module = get_scope_module(rec->scope); |
| 175 | if (scope_module) { |
| 176 | auto builtins = reinterpret_borrow<dict>(PyEval_GetBuiltins()); |
| 177 | auto builtins_eval = builtins["eval"]; |
| 178 | auto reconstruct_args = make_tuple(str("__import__('importlib').import_module('") |
| 179 | + scope_module + str("')")); |
| 180 | return make_tuple(std::move(builtins_eval), std::move(reconstruct_args)) |
| 181 | .release() |
| 182 | .ptr(); |
| 183 | } |
| 184 | } |
| 185 | set_error(PyExc_RuntimeError, repr(self) + str(" is not pickleable.")); |
| 186 | return nullptr; |
| 187 | } |
| 188 | |
| 189 | PYBIND11_NAMESPACE_END(function_record_PyTypeObject_methods) |
| 190 |
nothing calls this directly
no test coverage detected