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

Method repr

crates/vm/src/stdlib/_collections.rs:562–585  ·  view source on GitHub ↗
(zelf: &Py<Self>, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

560 impl Representable for PyDeque {
561 #[inline]
562 fn repr(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyRef<PyStr>> {
563 let deque = zelf.borrow_deque().clone();
564 let class = zelf.class();
565 let class_name = class.name();
566 let closing_part = zelf
567 .maxlen
568 .map(|maxlen| format!("], maxlen={maxlen}"))
569 .unwrap_or_else(|| "]".to_owned());
570
571 if zelf.__len__() == 0 {
572 return Ok(vm.ctx.new_str(format!("{class_name}([{closing_part})")));
573 }
574 if let Some(_guard) = ReprGuard::enter(vm, zelf.as_object()) {
575 Ok(vm.ctx.new_str(collection_repr(
576 Some(&class_name),
577 "[",
578 &closing_part,
579 deque.iter(),
580 vm,
581 )?))
582 } else {
583 Ok(vm.ctx.intern_str("[...]").to_owned())
584 }
585 }
586
587 fn repr_str(_zelf: &Py<Self>, _vm: &VirtualMachine) -> PyResult<String> {
588 unreachable!("repr() is overridden directly")

Callers 1

indexMethod · 0.45

Calls 13

collection_reprFunction · 0.85
borrow_dequeMethod · 0.80
intern_strMethod · 0.80
SomeClass · 0.50
cloneMethod · 0.45
classMethod · 0.45
nameMethod · 0.45
mapMethod · 0.45
to_ownedMethod · 0.45
__len__Method · 0.45
new_strMethod · 0.45
as_objectMethod · 0.45

Tested by

no test coverage detected