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

Method repr_item

crates/vm/src/builtins/union.rs:61–89  ·  view source on GitHub ↗
(obj: PyObjectRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

59
60 fn repr(&self, vm: &VirtualMachine) -> PyResult<String> {
61 fn repr_item(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<String> {
62 if obj.is(vm.ctx.types.none_type) {
63 return Ok("None".to_string());
64 }
65
66 if vm
67 .get_attribute_opt(obj.clone(), identifier!(vm, __origin__))?
68 .is_some()
69 && vm
70 .get_attribute_opt(obj.clone(), identifier!(vm, __args__))?
71 .is_some()
72 {
73 return Ok(obj.repr(vm)?.to_string());
74 }
75
76 match (
77 vm.get_attribute_opt(obj.clone(), identifier!(vm, __qualname__))?
78 .and_then(|o| o.downcast_ref::<PyStr>().map(|n| n.to_string())),
79 vm.get_attribute_opt(obj.clone(), identifier!(vm, __module__))?
80 .and_then(|o| o.downcast_ref::<PyStr>().map(|m| m.to_string())),
81 ) {
82 (None, _) | (_, None) => Ok(obj.repr(vm)?.to_string()),
83 (Some(qualname), Some(module)) => Ok(if module == "builtins" {
84 qualname
85 } else {
86 format!("{module}.{qualname}")
87 }),
88 }
89 }
90
91 Ok(self
92 .args

Callers

nothing calls this directly

Calls 6

isMethod · 0.80
to_stringMethod · 0.80
get_attribute_optMethod · 0.80
cloneMethod · 0.45
reprMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected