Skip to content

Commit 0e7bb10

Browse files
committed
Use built-in eval() instead of function_record_pickle_helper()
Much simpler! (Note that the `function_record_pickle_helper()` code is NOT removed in this commit.) This approach was discovered in an attempt to solve the problem that stubgen picks up `_function_record_pickle_helper_v1`. For example (tensorflow_text/core/pybinds/tflite_registrar.pyi): ```diff +from typing import Any + +def _function_record_pickle_helper_v1(*args, **kwargs) -> Any: ... ```
1 parent 0d210a5 commit 0e7bb10

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

include/pybind11/detail/function_record_pyobject.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,9 @@ inline PyObject *reduce_ex_impl(PyObject *self, PyObject *, PyObject *) {
214214
&& PyModule_Check(rec->scope.ptr()) != 0) {
215215
object scope_module = get_scope_module(rec->scope);
216216
if (scope_module) {
217-
return make_tuple(get_function_record_pickle_helper(rec->scope),
218-
make_tuple(make_tuple(scope_module, rec->name)))
217+
return make_tuple(reinterpret_borrow<object>(PyEval_GetBuiltins())["eval"],
218+
make_tuple(str("__import__('importlib').import_module('")
219+
+ scope_module + str("')")))
219220
.release()
220221
.ptr();
221222
}

include/pybind11/pybind11.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,11 +561,6 @@ class cpp_function : public function {
561561
guarded_strdup.release();
562562

563563
object scope_module = detail::get_scope_module(rec->scope);
564-
if (rec->name != nullptr && rec->name[0] != '\0' && rec->scope
565-
&& PyModule_Check(rec->scope.ptr()) != 0 && scope_module) {
566-
// Call-once initialization.
567-
detail::get_function_record_pickle_helper(rec->scope);
568-
}
569564
m_ptr = PyCFunction_NewEx(rec->def, py_func_rec.ptr(), scope_module.ptr());
570565
if (!m_ptr) {
571566
pybind11_fail("cpp_function::cpp_function(): Could not allocate function object");

0 commit comments

Comments
 (0)