Skip to content

Commit 99b8d29

Browse files
authored
Merge pull request RustPython#3824 from oow214/fix_itertools_count_repr
Fix itertools count repr
2 parents df785b6 + 27a0d3a commit 99b8d29

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

vm/src/stdlib/itertools.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ mod decl {
1717
AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, PyWeakRef, VirtualMachine,
1818
};
1919
use crossbeam_utils::atomic::AtomicCell;
20-
use num_traits::{Signed, ToPrimitive};
20+
use num_traits::{Signed, ToPrimitive, One};
2121
use std::fmt;
2222

2323
#[pyattr]
@@ -220,10 +220,13 @@ mod decl {
220220
}
221221

222222
#[pymethod(magic)]
223-
fn repr(&self) -> PyResult<String> {
224-
let cur = self.cur.read();
225-
226-
Ok(format!("count({})", cur))
223+
fn repr(&self, vm: &VirtualMachine) -> PyResult<String> {
224+
let cur = format!("{}", self.cur.read().clone().repr(vm)?);
225+
let step = self.step.as_bigint();
226+
if step.is_one() {
227+
return Ok(format!("count({})", cur));
228+
}
229+
Ok(format!("count({}, {})", cur, step.to_string()))
227230
}
228231
}
229232
impl IterNextIterable for PyItertoolsCount {}

0 commit comments

Comments
 (0)