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

Method repr_str

crates/vm/src/builtins/classmethod.rs:201–222  ·  view source on GitHub ↗
(zelf: &Py<Self>, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

199impl Representable for PyClassMethod {
200 #[inline]
201 fn repr_str(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<String> {
202 let callable = zelf.callable.lock().repr(vm).unwrap();
203 let class = Self::class(&vm.ctx);
204
205 let repr = match (
206 class
207 .__qualname__(vm)
208 .downcast_ref::<PyStr>()
209 .map(|n| n.as_wtf8()),
210 class
211 .__module__(vm)
212 .downcast_ref::<PyStr>()
213 .map(|m| m.as_wtf8()),
214 ) {
215 (None, _) => return Err(vm.new_type_error("Unknown qualified name")),
216 (Some(qualname), Some(module)) if module != "builtins" => {
217 format!("<{module}.{qualname}({callable})>")
218 }
219 _ => format!("<{}({})>", class.slot_name(), callable),
220 };
221 Ok(repr)
222 }
223}
224
225pub(crate) fn init(context: &'static Context) {

Callers

nothing calls this directly

Calls 8

ErrClass · 0.50
unwrapMethod · 0.45
reprMethod · 0.45
lockMethod · 0.45
mapMethod · 0.45
__qualname__Method · 0.45
as_wtf8Method · 0.45
__module__Method · 0.45

Tested by

no test coverage detected