(py: Python, obj: PyObject)
| 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>()`. |
nothing calls this directly
no test coverage detected