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

Method map_py_iter

crates/vm/src/vm/mod.rs:1902–1926  ·  view source on GitHub ↗
(&self, value: &PyObject, mut f: F)

Source from the content-addressed store, hash-verified

1900 }
1901
1902 fn map_py_iter<F, R>(&self, value: &PyObject, mut f: F) -> PyResult<Vec<R>>
1903 where
1904 F: FnMut(PyObjectRef) -> PyResult<R>,
1905 {
1906 let iter = value.to_owned().get_iter(self)?;
1907 let cap = match self.length_hint_opt(value.to_owned()) {
1908 Err(e) if e.class().is(self.ctx.exceptions.runtime_error) => return Err(e),
1909 Ok(Some(value)) => Some(value),
1910 // Use a power of 2 as a default capacity.
1911 _ => None,
1912 };
1913 // TODO: fix extend to do this check (?), see test_extend in Lib/test/list_tests.py,
1914 // https://github.com/python/cpython/blob/v3.9.0/Objects/listobject.c#L922-L928
1915 if let Some(cap) = cap
1916 && cap >= isize::MAX as usize
1917 {
1918 return Ok(Vec::new());
1919 }
1920
1921 let mut results = PyIterIter::new(self, iter.as_ref(), cap)
1922 .map(|element| f(element?))
1923 .collect::<PyResult<Vec<_>>>()?;
1924 results.shrink_to_fit();
1925 Ok(results)
1926 }
1927
1928 pub fn get_attribute_opt<'a>(
1929 &self,

Callers 1

extract_elements_withMethod · 0.80

Calls 12

newFunction · 0.85
get_iterMethod · 0.80
length_hint_optMethod · 0.80
isMethod · 0.80
shrink_to_fitMethod · 0.80
ErrClass · 0.50
SomeClass · 0.50
fFunction · 0.50
to_ownedMethod · 0.45
classMethod · 0.45
mapMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected