MCPcopy Create free account
hub / github.com/BasisResearch/lean.py / make_callable_obj

Function make_callable_obj

LeanPy/native/python_bridge.c:1023–1045  ·  view source on GitHub ↗

Allocate a LeanCallableObject of the given variant and bind the closure * (transferring ownership). Wraps the resulting Python object as a Lean * `Py` via wrap_pyobject so the Lean side sees it as just another Py. */

Source from the content-addressed store, hash-verified

1021 "Lean closure returned a NULL Py object");
1022 }
1023 return NULL;
1024 }
1025 return out;
1026}
1027
1028/* Allocate a LeanCallableObject of the given variant and bind the closure
1029 * (transferring ownership). Wraps the resulting Python object as a Lean
1030 * `Py` via wrap_pyobject so the Lean side sees it as just another Py. */
1031static lean_object *make_callable_obj(lean_obj_arg closure, int has_kw) {
1032 if (!py_initialized) {
1033 lean_dec(closure);
1034 return raise_io_error(
1035 "LeanPy.Python.Py.fromLeanCallable: Python not initialized; "
1036 "call LeanPy.Python.init first");
1037 }
1038 PyObject *type = get_lean_callable_type(has_kw);
1039 if (!type) {
1040 lean_dec(closure);
1041 return raise_io_error(
1042 "LeanPy.Python.Py.fromLeanCallable: failed to create type");
1043 }
1044 PyObject *instance = p_PyType_GenericAlloc(type, 0);
1045 if (!instance) {
1046 lean_dec(closure);
1047 return raise_py_error();
1048 }

Callers 2

leanpy_make_callableFunction · 0.85
leanpy_make_callable_kwFunction · 0.85

Calls 5

lean_decFunction · 0.85
raise_io_errorFunction · 0.85
get_lean_callable_typeFunction · 0.85
raise_py_errorFunction · 0.85
wrap_pyobjectFunction · 0.85

Tested by

no test coverage detected