Skip to content

Commit 3d8cac3

Browse files
committed
Fix some failing tests
1 parent 3d52ed7 commit 3d8cac3

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

Lib/test/test_itertools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ def test_compress(self):
602602
next(testIntermediate)
603603
self.assertEqual(list(op(testIntermediate)), list(result2))
604604

605-
@unittest.expectedFailure # TODO: RUSTPYTHON
605+
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: DeprecationWarning not triggered
606606
@pickle_deprecated
607607
def test_count(self):
608608
self.assertEqual(lzip('abc',count()), [('a', 0), ('b', 1), ('c', 2)])

vm/src/stdlib/itertools.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@ mod decl {
238238

239239
#[derive(FromArgs)]
240240
struct CountNewArgs {
241-
#[pyarg(positional, optional)]
241+
#[pyarg(any, optional)]
242242
start: OptionalArg<PyObjectRef>,
243243

244-
#[pyarg(positional, optional)]
244+
#[pyarg(any, optional)]
245245
step: OptionalArg<PyObjectRef>,
246246
}
247247

@@ -1945,6 +1945,7 @@ mod decl {
19451945
exhausted: AtomicCell<bool>,
19461946
iterable: PyIter,
19471947
n: AtomicCell<usize>,
1948+
strict: AtomicCell<bool>,
19481949
}
19491950

19501951
#[derive(FromArgs)]
@@ -1953,14 +1954,20 @@ mod decl {
19531954
iterable_ref: PyObjectRef,
19541955
#[pyarg(positional)]
19551956
n: PyIntRef,
1957+
#[pyarg(named, default = false)]
1958+
strict: bool,
19561959
}
19571960

19581961
impl Constructor for PyItertoolsBatched {
19591962
type Args = BatchedNewArgs;
19601963

19611964
fn py_new(
19621965
cls: PyTypeRef,
1963-
Self::Args { iterable_ref, n }: Self::Args,
1966+
Self::Args {
1967+
iterable_ref,
1968+
n,
1969+
strict,
1970+
}: Self::Args,
19641971
vm: &VirtualMachine,
19651972
) -> PyResult {
19661973
let n = n.as_bigint();
@@ -1976,6 +1983,7 @@ mod decl {
19761983
iterable,
19771984
n: AtomicCell::new(n),
19781985
exhausted: AtomicCell::new(false),
1986+
strict: AtomicCell::new(strict),
19791987
}
19801988
.into_ref_with_type(vm, cls)
19811989
.map(Into::into)
@@ -2005,9 +2013,16 @@ mod decl {
20052013
}
20062014
}
20072015
}
2008-
match result.len() {
2016+
let res_len = result.len();
2017+
match res_len {
20092018
0 => Ok(PyIterReturn::StopIteration(None)),
2010-
_ => Ok(PyIterReturn::Return(vm.ctx.new_tuple(result).into())),
2019+
_ => {
2020+
if zelf.strict.load() && res_len != n {
2021+
Err(vm.new_value_error("batched(): incomplete batch"))
2022+
} else {
2023+
Ok(PyIterReturn::Return(vm.ctx.new_tuple(result).into()))
2024+
}
2025+
}
20112026
}
20122027
}
20132028
}

0 commit comments

Comments
 (0)