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

Function try_get_cpp_conduit_method

include/pybind11/detail/cpp_conduit.h:33–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31}
32
33inline object try_get_cpp_conduit_method(PyObject *obj) {
34 if (PyType_Check(obj)) {
35 return object();
36 }
37 PyTypeObject *type_obj = Py_TYPE(obj);
38 str attr_name("_pybind11_conduit_v1_");
39 bool assumed_to_be_callable = false;
40 if (type_is_managed_by_our_internals(type_obj)) {
41 if (!is_instance_method_of_type(type_obj, attr_name.ptr())) {
42 return object();
43 }
44 assumed_to_be_callable = true;
45 }
46 PyObject *method = PyObject_GetAttr(obj, attr_name.ptr());
47 if (method == nullptr) {
48 PyErr_Clear();
49 return object();
50 }
51 if (!assumed_to_be_callable && PyCallable_Check(method) == 0) {
52 Py_DECREF(method);
53 return object();
54 }
55 return reinterpret_steal<object>(method);
56}
57
58inline void *try_raw_pointer_ephemeral_from_cpp_conduit(handle src,
59 const std::type_info *cpp_type_info) {

Calls 4

ptrMethod · 0.80
objectFunction · 0.50

Tested by

no test coverage detected