MCPcopy Create free account
hub / github.com/alibaba/zvec / checked_cast

Function checked_cast

src/binding/python/model/python_doc.cc:22–32  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20
21template <typename T>
22T checked_cast(const py::object &obj, const std::string &field,
23 const std::string &expected_type) {
24 try {
25 return obj.cast<T>();
26 } catch (const py::cast_error &e) {
27 std::string actual_type = std::string(py::str(py::type::of(obj)));
28 std::string msg = "Field '" + field + "': expected " + expected_type +
29 ", got " + actual_type;
30 throw py::type_error(msg);
31 }
32}
33
34void ZVecPyDoc::Initialize(pybind11::module_ &m) {
35 bind_doc_operator(m);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected