Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix some failing tests
  • Loading branch information
ShaharNaveh committed Sep 2, 2025
commit 3d8cac3e8e5578dca2dbd2b0c5931c666c0aaf3b
2 changes: 1 addition & 1 deletion Lib/test/test_itertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ def test_compress(self):
next(testIntermediate)
self.assertEqual(list(op(testIntermediate)), list(result2))

@unittest.expectedFailure # TODO: RUSTPYTHON
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: DeprecationWarning not triggered
@pickle_deprecated
def test_count(self):
self.assertEqual(lzip('abc',count()), [('a', 0), ('b', 1), ('c', 2)])
Expand Down
25 changes: 20 additions & 5 deletions vm/src/stdlib/itertools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ mod decl {

#[derive(FromArgs)]
struct CountNewArgs {
#[pyarg(positional, optional)]
#[pyarg(any, optional)]
start: OptionalArg<PyObjectRef>,

#[pyarg(positional, optional)]
#[pyarg(any, optional)]
step: OptionalArg<PyObjectRef>,
}

Expand Down Expand Up @@ -1945,6 +1945,7 @@ mod decl {
exhausted: AtomicCell<bool>,
iterable: PyIter,
n: AtomicCell<usize>,
strict: AtomicCell<bool>,
}

#[derive(FromArgs)]
Expand All @@ -1953,14 +1954,20 @@ mod decl {
iterable_ref: PyObjectRef,
#[pyarg(positional)]
n: PyIntRef,
#[pyarg(named, default = false)]
strict: bool,
}

impl Constructor for PyItertoolsBatched {
type Args = BatchedNewArgs;

fn py_new(
cls: PyTypeRef,
Self::Args { iterable_ref, n }: Self::Args,
Self::Args {
iterable_ref,
n,
strict,
}: Self::Args,
vm: &VirtualMachine,
) -> PyResult {
let n = n.as_bigint();
Expand All @@ -1976,6 +1983,7 @@ mod decl {
iterable,
n: AtomicCell::new(n),
exhausted: AtomicCell::new(false),
strict: AtomicCell::new(strict),
}
.into_ref_with_type(vm, cls)
.map(Into::into)
Expand Down Expand Up @@ -2005,9 +2013,16 @@ mod decl {
}
}
}
match result.len() {
let res_len = result.len();
match res_len {
0 => Ok(PyIterReturn::StopIteration(None)),
_ => Ok(PyIterReturn::Return(vm.ctx.new_tuple(result).into())),
_ => {
if zelf.strict.load() && res_len != n {
Err(vm.new_value_error("batched(): incomplete batch"))
} else {
Ok(PyIterReturn::Return(vm.ctx.new_tuple(result).into()))
}
}
}
}
}
Expand Down
Loading