MCPcopy Create free account
hub / github.com/pybind/pybind11 / reduce_ex_impl

Function reduce_ex_impl

include/pybind11/detail/function_record_pyobject.h:165–187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163}
164
165inline 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
189PYBIND11_NAMESPACE_END(function_record_PyTypeObject_methods)
190

Callers

nothing calls this directly

Calls 9

get_scope_moduleFunction · 0.85
make_tupleFunction · 0.85
strClass · 0.85
moveFunction · 0.85
reprFunction · 0.85
ptrMethod · 0.80
releaseMethod · 0.80
set_errorFunction · 0.50

Tested by

no test coverage detected