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

Method get_single_attr

crates/vm/src/stdlib/_operator.rs:374–390  ·  view source on GitHub ↗

Go through dotted parts of string and call getattr on whatever is returned.

(
            obj: PyObjectRef,
            attr: &Py<PyStr>,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

372
373 // Go through dotted parts of string and call getattr on whatever is returned.
374 fn get_single_attr(
375 obj: PyObjectRef,
376 attr: &Py<PyStr>,
377 vm: &VirtualMachine,
378 ) -> PyResult<PyObjectRef> {
379 let attr_str = attr.as_bytes();
380 let parts = attr_str.split(|&b| b == b'.').collect::<Vec<_>>();
381 if parts.len() == 1 {
382 return obj.get_attr(attr, vm);
383 }
384 let mut obj = obj;
385 for part in parts {
386 let part = Wtf8::from_bytes(part).expect("originally valid WTF-8");
387 obj = obj.get_attr(&vm.ctx.new_str(part), vm)?;
388 }
389 Ok(obj)
390 }
391 }
392
393 impl Constructor for PyAttrGetter {

Callers

nothing calls this directly

Calls 5

as_bytesMethod · 0.45
splitMethod · 0.45
lenMethod · 0.45
get_attrMethod · 0.45
new_strMethod · 0.45

Tested by

no test coverage detected