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

Method repr_arg

crates/vm/src/builtins/genericalias.rs:150–169  ·  view source on GitHub ↗
(obj: PyObjectRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

148 }
149
150 fn repr_arg(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<String> {
151 // ParamSpec args can be lists - format their items with repr_item
152 if obj.class().is(vm.ctx.types.list_type) {
153 let list = obj.downcast_ref::<crate::builtins::PyList>().unwrap();
154 let len = list.borrow_vec().len();
155 let mut parts = Vec::with_capacity(len);
156 // Use indexed access so list mutation during repr causes IndexError
157 for i in 0..len {
158 let item = list
159 .borrow_vec()
160 .get(i)
161 .cloned()
162 .ok_or_else(|| vm.new_index_error("list index out of range"))?;
163 parts.push(repr_item(item, vm)?);
164 }
165 Ok(format!("[{}]", parts.join(", ")))
166 } else {
167 repr_item(obj, vm)
168 }
169 }
170
171 let repr_str = format!(
172 "{}[{}]",

Callers

nothing calls this directly

Calls 8

isMethod · 0.80
borrow_vecMethod · 0.80
ok_or_elseMethod · 0.80
classMethod · 0.45
unwrapMethod · 0.45
lenMethod · 0.45
getMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected