(zelf: &PyObject, vm: &VirtualMachine)
| 203 | |
| 204 | #[pyslot] |
| 205 | fn slot_repr(zelf: &PyObject, vm: &VirtualMachine) -> PyResult<PyStrRef> { |
| 206 | let zelf = zelf |
| 207 | .downcast_ref::<PyBaseException>() |
| 208 | .expect("exception group must be BaseException"); |
| 209 | let class_name = zelf.class().name().to_owned(); |
| 210 | let message = zelf.get_arg(0).map(|m| m.repr(vm)).transpose()?; |
| 211 | |
| 212 | let mut result = Wtf8Buf::new(); |
| 213 | write!(result, "{class_name}(").unwrap(); |
| 214 | let message_wtf8: &Wtf8 = message.as_ref().map_or("''".as_ref(), |s| s.as_wtf8()); |
| 215 | result.push_wtf8(message_wtf8); |
| 216 | result.push_str(", ["); |
| 217 | if let Some(exceptions_obj) = zelf.get_arg(1) { |
| 218 | let iter: ArgIterable<PyObjectRef> = |
| 219 | ArgIterable::try_from_object(vm, exceptions_obj.clone())?; |
| 220 | let mut first = true; |
| 221 | for exc in iter.iter(vm)? { |
| 222 | if !first { |
| 223 | result.push_str(", "); |
| 224 | } |
| 225 | first = false; |
| 226 | result.push_wtf8(exc?.repr(vm)?.as_wtf8()); |
| 227 | } |
| 228 | } |
| 229 | result.push_str("])"); |
| 230 | |
| 231 | Ok(vm.ctx.new_str(result)) |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | impl Constructor for PyBaseExceptionGroup { |
nothing calls this directly
no test coverage detected