MCPcopy Index your code
hub / github.com/RustPython/RustPython / slot_repr

Method slot_repr

crates/vm/src/exception_group.rs:205–232  ·  view source on GitHub ↗
(zelf: &PyObject, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls 15

newFunction · 0.85
push_wtf8Method · 0.80
to_ownedMethod · 0.45
nameMethod · 0.45
classMethod · 0.45
mapMethod · 0.45
get_argMethod · 0.45
reprMethod · 0.45
unwrapMethod · 0.45
as_refMethod · 0.45
as_wtf8Method · 0.45
push_strMethod · 0.45

Tested by

no test coverage detected