@@ -17,7 +17,7 @@ mod decl {
17
17
AsObject , Py , PyObjectRef , PyPayload , PyRef , PyResult , PyWeakRef , VirtualMachine ,
18
18
} ;
19
19
use crossbeam_utils:: atomic:: AtomicCell ;
20
- use num_traits:: { One , Signed , ToPrimitive } ;
20
+ use num_traits:: { Signed , ToPrimitive } ;
21
21
use std:: fmt;
22
22
23
23
#[ pyattr]
@@ -174,7 +174,7 @@ mod decl {
174
174
#[ derive( Debug , PyPayload ) ]
175
175
struct PyItertoolsCount {
176
176
cur : PyRwLock < PyObjectRef > ,
177
- step : PyIntRef ,
177
+ step : PyObjectRef ,
178
178
}
179
179
180
180
#[ derive( FromArgs ) ]
@@ -183,7 +183,7 @@ mod decl {
183
183
start : OptionalArg < PyObjectRef > ,
184
184
185
185
#[ pyarg( positional, optional) ]
186
- step : OptionalArg < PyIntRef > ,
186
+ step : OptionalArg < PyObjectRef > ,
187
187
}
188
188
189
189
impl Constructor for PyItertoolsCount {
@@ -194,9 +194,9 @@ mod decl {
194
194
Self :: Args { start, step } : Self :: Args ,
195
195
vm : & VirtualMachine ,
196
196
) -> PyResult {
197
- let start: PyObjectRef = start. into_option ( ) . unwrap_or_else ( || vm. new_pyobj ( 0 ) ) ;
198
- let step: PyIntRef = step. into_option ( ) . unwrap_or_else ( || vm. new_pyref ( 1 ) ) ;
199
- if !PyNumber :: check ( & start, vm) {
197
+ let start = start. into_option ( ) . unwrap_or_else ( || vm. new_pyobj ( 0 ) ) ;
198
+ let step = step. into_option ( ) . unwrap_or_else ( || vm. new_pyobj ( 1 ) ) ;
199
+ if !PyNumber :: check ( & start, vm) || ! PyNumber :: check ( & step , vm ) {
200
200
return Err ( vm. new_value_error ( "a number is require" . to_owned ( ) ) ) ;
201
201
}
202
202
@@ -222,11 +222,11 @@ mod decl {
222
222
#[ pymethod( magic) ]
223
223
fn repr ( & self , vm : & VirtualMachine ) -> PyResult < String > {
224
224
let cur = format ! ( "{}" , self . cur. read( ) . clone( ) . repr( vm) ?) ;
225
- let step = self . step . as_bigint ( ) ;
226
- if step. is_one ( ) {
225
+ let step = & self . step ;
226
+ if vm . bool_eq ( step, vm . ctx . new_int ( 1 ) . as_object ( ) ) ? {
227
227
return Ok ( format ! ( "count({})" , cur) ) ;
228
228
}
229
- Ok ( format ! ( "count({}, {})" , cur, step) )
229
+ Ok ( format ! ( "count({}, {})" , cur, step. repr ( vm ) ? ) )
230
230
}
231
231
}
232
232
impl IterNextIterable for PyItertoolsCount { }
0 commit comments