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

Method getattro

crates/vm/src/builtins/type.rs:2318–2365  ·  view source on GitHub ↗
(zelf: &Py<Self>, name_str: &Py<PyStr>, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

2316
2317impl GetAttr for PyType {
2318 fn getattro(zelf: &Py<Self>, name_str: &Py<PyStr>, vm: &VirtualMachine) -> PyResult {
2319 #[cold]
2320 fn attribute_error(
2321 zelf: &Py<PyType>,
2322 name: &Wtf8,
2323 vm: &VirtualMachine,
2324 ) -> PyBaseExceptionRef {
2325 vm.new_attribute_error(format!(
2326 "type object '{}' has no attribute '{}'",
2327 zelf.slot_name(),
2328 name,
2329 ))
2330 }
2331
2332 let Some(name) = vm.ctx.interned_str(name_str) else {
2333 return Err(attribute_error(zelf, name_str.as_wtf8(), vm));
2334 };
2335 vm_trace!("type.__getattribute__({:?}, {:?})", zelf, name);
2336 let mcl = zelf.class();
2337 let mcl_attr = mcl.get_attr(name);
2338
2339 if let Some(ref attr) = mcl_attr {
2340 let attr_class = attr.class();
2341 let has_descr_set = attr_class.slots.descr_set.load().is_some();
2342 if has_descr_set {
2343 let descr_get = attr_class.slots.descr_get.load();
2344 if let Some(descr_get) = descr_get {
2345 let mcl = mcl.to_owned().into();
2346 return descr_get(attr.clone(), Some(zelf.to_owned().into()), Some(mcl), vm);
2347 }
2348 }
2349 }
2350
2351 let zelf_attr = zelf.get_attr(name);
2352
2353 if let Some(attr) = zelf_attr {
2354 let descr_get = attr.class().slots.descr_get.load();
2355 if let Some(descr_get) = descr_get {
2356 descr_get(attr, None, Some(zelf.to_owned().into()), vm)
2357 } else {
2358 Ok(attr)
2359 }
2360 } else if let Some(attr) = mcl_attr {
2361 vm.call_if_get_descriptor(&attr, zelf.to_owned().into())
2362 } else {
2363 Err(attribute_error(zelf, name_str.as_wtf8(), vm))
2364 }
2365 }
2366}
2367
2368#[pyclass]

Callers

nothing calls this directly

Calls 10

interned_strMethod · 0.80
ErrClass · 0.50
SomeClass · 0.50
as_wtf8Method · 0.45
classMethod · 0.45
get_attrMethod · 0.45
loadMethod · 0.45
to_ownedMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected