| 43 | // Returns strerror attribute if available, otherwise str(args) |
| 44 | #[pymethod] |
| 45 | fn __str__(exc: &Py<PyBaseException>, vm: &VirtualMachine) -> PyResult<PyStrRef> { |
| 46 | use crate::vm::AsObject; |
| 47 | // Try to get strerror attribute first (OSError compatibility) |
| 48 | if let Ok(strerror) = exc.as_object().get_attr("strerror", vm) |
| 49 | && !vm.is_none(&strerror) |
| 50 | { |
| 51 | return strerror.str(vm); |
| 52 | } |
| 53 | |
| 54 | // Otherwise return str(args) |
| 55 | let args = exc.args(); |
| 56 | if args.len() == 1 { |
| 57 | args.as_slice()[0].str(vm) |
| 58 | } else { |
| 59 | args.as_object().str(vm) |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | #[pyattr] |