(zelf: &Py<Self>, vm: &VirtualMachine)
| 140 | impl 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 | |
| 178 | pub fn init(context: &'static Context) { |
nothing calls this directly
no test coverage detected