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

Method try_from_object

crates/vm/src/protocol/iter.rs:127–147  ·  view source on GitHub ↗

This helper function is called at multiple places. First, it is called in the vm when a for loop is entered. Next, it is used when the builtin function 'iter' is called.

(vm: &VirtualMachine, iter_target: PyObjectRef)

Source from the content-addressed store, hash-verified

125 // in the vm when a for loop is entered. Next, it is used when the builtin
126 // function 'iter' is called.
127 fn try_from_object(vm: &VirtualMachine, iter_target: PyObjectRef) -> PyResult<Self> {
128 let get_iter = iter_target.class().slots.iter.load();
129 if let Some(get_iter) = get_iter {
130 let iter = get_iter(iter_target, vm)?;
131 if Self::check(&iter) {
132 Ok(Self(iter))
133 } else {
134 Err(vm.new_type_error(format!(
135 "iter() returned non-iterator of type '{}'",
136 iter.class().name()
137 )))
138 }
139 } else if let Ok(seq_iter) = PySequenceIterator::new(iter_target.clone(), vm) {
140 Ok(Self(seq_iter.into_pyobject(vm)))
141 } else {
142 Err(vm.new_type_error(format!(
143 "'{}' object is not iterable",
144 iter_target.class().name()
145 )))
146 }
147 }
148}
149
150#[derive(result_like::ResultLike)]

Callers

nothing calls this directly

Calls 8

SelfFunction · 0.85
newFunction · 0.85
checkFunction · 0.50
ErrClass · 0.50
loadMethod · 0.45
classMethod · 0.45
cloneMethod · 0.45
into_pyobjectMethod · 0.45

Tested by

no test coverage detected