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

Method next

crates/vm/src/builtins/zip.rs:76–113  ·  view source on GitHub ↗
(zelf: &Py<Self>, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

74impl SelfIter for PyZip {}
75impl IterNext for PyZip {
76 fn next(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
77 if zelf.iterators.is_empty() {
78 return Ok(PyIterReturn::StopIteration(None));
79 }
80 let mut next_objs = Vec::new();
81 for (idx, iterator) in zelf.iterators.iter().enumerate() {
82 let item = match iterator.next(vm)? {
83 PyIterReturn::Return(obj) => obj,
84 PyIterReturn::StopIteration(v) => {
85 if zelf.strict.load(atomic::Ordering::Acquire) {
86 if idx > 0 {
87 let plural = if idx == 1 { " " } else { "s 1-" };
88 return Err(vm.new_value_error(format!(
89 "zip() argument {} is shorter than argument{}{}",
90 idx + 1,
91 plural,
92 idx
93 )));
94 }
95 for (idx, iterator) in zelf.iterators[1..].iter().enumerate() {
96 if let PyIterReturn::Return(_obj) = iterator.next(vm)? {
97 let plural = if idx == 0 { " " } else { "s 1-" };
98 return Err(vm.new_value_error(format!(
99 "zip() argument {} is longer than argument{}{}",
100 idx + 2,
101 plural,
102 idx + 1
103 )));
104 }
105 }
106 }
107 return Ok(PyIterReturn::StopIteration(v));
108 }
109 };
110 next_objs.push(item);
111 }
112 Ok(PyIterReturn::Return(vm.ctx.new_tuple(next_objs).into()))
113 }
114}
115
116pub fn init(ctx: &'static Context) {

Callers

nothing calls this directly

Calls 7

newFunction · 0.85
ErrClass · 0.50
is_emptyMethod · 0.45
iterMethod · 0.45
loadMethod · 0.45
pushMethod · 0.45
new_tupleMethod · 0.45

Tested by

no test coverage detected