MCPcopy Create free account
hub / github.com/dgrunwald/rust-cpython / from_instance_helper

Method from_instance_helper

src/err.rs:268–294  ·  view source on GitHub ↗
(py: Python, obj: PyObject)

Source from the content-addressed store, hash-verified

266 }
267
268 fn from_instance_helper(py: Python, obj: PyObject) -> PyErr {
269 if unsafe { ffi::PyExceptionInstance_Check(obj.as_ptr()) } != 0 {
270 PyErr {
271 ptype: unsafe {
272 PyObject::from_borrowed_ptr(py, ffi::PyExceptionInstance_Class(obj.as_ptr()))
273 },
274 pvalue: Some(obj),
275 ptraceback: None,
276 }
277 } else if unsafe { ffi::PyExceptionClass_Check(obj.as_ptr()) } != 0 {
278 PyErr {
279 ptype: obj,
280 pvalue: None,
281 ptraceback: None,
282 }
283 } else {
284 PyErr {
285 ptype: py.get_type::<exc::TypeError>().into_object(),
286 pvalue: Some(
287 "exceptions must derive from BaseException"
288 .to_py_object(py)
289 .into_object(),
290 ),
291 ptraceback: None,
292 }
293 }
294 }
295
296 /// Construct a new error, with the usual lazy initialization of Python exceptions.
297 /// `exc` is the exception type; usually one of the standard exceptions like `py.get_type::<exc::RuntimeError>()`.

Callers

nothing calls this directly

Calls 6

PyExceptionClass_CheckFunction · 0.50
as_ptrMethod · 0.45
into_objectMethod · 0.45
to_py_objectMethod · 0.45

Tested by

no test coverage detected