8000 CPython Compliance: throw ValueError before TypeError · RustPython/RustPython@25fac31 · GitHub
[go: up one dir, main page]

Skip to content

Commit 25fac31

Browse files
committed
CPython Compliance: throw ValueError before TypeError
1 parent 8eb3af1 commit 25fac31

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

vm/src/stdlib/itertools.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ mod decl {
2222
VirtualMachine,
2323
};
2424
use crossbeam_utils::atomic::AtomicCell;
25+
use malachite_bigint::BigInt;
26+
use num_traits::One;
27+
2528
use num_traits::{Signed, ToPrimitive};
2629
use std::fmt;
2730

@@ -1965,7 +1968,7 @@ mod decl {
19651968
#[derive(FromArgs)]
19661969
struct BatchedNewArgs {
19671970
#[pyarg(positional)]
1968-
iterable: PyIter,
1971+
iterable_ref: PyObjectRef,
19691972
#[pyarg(positional)]
19701973
n: PyIntRef,
19711974
}
@@ -1975,14 +1978,18 @@ mod decl {
19751978

19761979
fn py_new(
19771980
cls: PyTypeRef,
1978-
Self::Args { iterable, n }: Self::Args,
1981+
Self::Args { iterable_ref, n }: Self::Args,
19791982
vm: &VirtualMachine,
19801983
) -> PyResult {
19811984
let n = n.as_bigint();
1982-
if n.is_negative() {
1985+
if n.lt(&BigInt::one()) {
19831986
return Err(vm.new_value_error("n must be at least one".to_owned()));
19841987
}
19851988
let n = n.to_usize().unwrap();
1989+
let iterable = match iterable_ref.get_iter(vm) {
1990+
Ok(it) => it,
1991+
Err(e) => return Err(e),
1992+
};
19861993

19871994
Self {
19881995
iterable,

0 commit comments

Comments
 (0)
0