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

Method repr_wtf8

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

Source from the content-addressed store, hash-verified

140impl Representable for PyNamespace {
141 #[inline]
142 fn repr_wtf8(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<Wtf8Buf> {
143 let o = zelf.as_object();
144 let name = if o.class().is(vm.ctx.types.namespace_type) {
145 "namespace".to_owned()
146 } else {
147 o.class().slot_name().to_owned()
148 };
149
150 let repr = if let Some(_guard) = ReprGuard::enter(vm, zelf.as_object()) {
151 let dict = zelf.as_object().dict().unwrap();
152 let mut result = Wtf8Buf::from(format!("{name}("));
153 let mut first = true;
154 for (key, value) in dict {
155 let Some(key_str) = key.downcast_ref::<PyStr>() else {
156 continue;
157 };
158 if key_str.as_wtf8().is_empty() {
159 continue;
160 }
161 if !first {
162 result.push_str(", ");
163 }
164 first = false;
165 result.push_wtf8(key_str.as_wtf8());
166 result.push_char('=');
167 result.push_wtf8(value.repr(vm)?.as_wtf8());
168 }
169 result.push_char(')');
170 result
171 } else {
172 Wtf8Buf::from(format!("{name}(...)"))
173 };
174 Ok(repr)
175 }
176}
177
178pub fn init(context: &'static Context) {

Callers

nothing calls this directly

Calls 13

isMethod · 0.80
push_wtf8Method · 0.80
as_objectMethod · 0.45
classMethod · 0.45
to_ownedMethod · 0.45
slot_nameMethod · 0.45
unwrapMethod · 0.45
dictMethod · 0.45
is_emptyMethod · 0.45
as_wtf8Method · 0.45
push_strMethod · 0.45
push_charMethod · 0.45

Tested by

no test coverage detected