(vm: &VirtualMachine, obj: PyObjectRef)
| 418 | |
| 419 | impl TryFromObject for ExceptionCtor { |
| 420 | fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> { |
| 421 | obj.downcast::<PyType>() |
| 422 | .and_then(|cls| { |
| 423 | if cls.fast_issubclass(vm.ctx.exceptions.base_exception_type) { |
| 424 | Ok(Self::Class(cls)) |
| 425 | } else { |
| 426 | Err(cls.into()) |
| 427 | } |
| 428 | }) |
| 429 | .or_else(|obj| obj.downcast::<PyBaseException>().map(Self::Instance)) |
| 430 | .map_err(|obj| { |
| 431 | vm.new_type_error(format!( |
| 432 | "exceptions must be classes or instances deriving from BaseException, not {}", |
| 433 | obj.class().name() |
| 434 | )) |
| 435 | }) |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | impl ExceptionCtor { |
nothing calls this directly
no test coverage detected