@@ -2,21 +2,23 @@ pub(crate) use decl::make_module;
2
2
3
3
#[ pymodule( name = "itertools" ) ]
4
4
mod decl {
5
- use crate :: common:: {
6
- lock:: { PyMutex , PyRwLock , PyRwLockWriteGuard } ,
7
- rc:: PyRc ,
8
- } ;
9
5
use crate :: {
10
6
builtins:: { int, PyGenericAlias , PyInt , PyIntRef , PyList , PyTuple , PyTupleRef , PyTypeRef } ,
7
+ common:: {
8
+ lock:: { PyMutex , PyRwLock , PyRwLockWriteGuard } ,
9
+ rc:: PyRc ,
10
+ } ,
11
11
convert:: ToPyObject ,
12
- function:: { ArgCallable , FuncArgs , OptionalArg , OptionalOption , PosArgs } ,
12
+ function:: { ArgCallable , ArgIntoBool , FuncArgs , OptionalArg , OptionalOption , PosArgs } ,
13
13
identifier,
14
14
protocol:: { PyIter , PyIterReturn , PyNumber } ,
15
15
stdlib:: sys,
16
16
types:: { Constructor , IterNext , IterNextIterable } ,
17
- AsObject , Py , PyObjectRef , PyPayload , PyRef , PyResult , PyWeakRef , VirtualMachine ,
17
+ AsObject , Py , PyObjectRef , PyPayload , PyRef , PyResult , PyWeakRef , TryFromObject ,
18
+ VirtualMachine ,
18
19
} ;
19
20
use crossbeam_utils:: atomic:: AtomicCell ;
21
+ use num_bigint:: BigInt ;
20
22
use num_traits:: { Signed , ToPrimitive } ;
21
23
use std:: fmt;
22
24
@@ -540,7 +542,23 @@ mod decl {
540
542
}
541
543
542
544
#[ pyclass( with( IterNext , Constructor ) , flags( BASETYPE ) ) ]
543
- impl PyItertoolsDropwhile { }
545
+ impl PyItertoolsDropwhile {
546
+ #[ pymethod( magic) ]
547
+ fn reduce ( zelf : PyRef < Self > ) -> ( PyTypeRef , ( PyObjectRef , PyIter ) , BigInt ) {
548
+ (
549
+ zelf. class ( ) . clone ( ) ,
550
+ ( zelf. predicate . clone ( ) . into ( ) , zelf. iterable . clone ( ) ) ,
551
+ ( if zelf. start_flag . load ( ) { 1 } else { 0 } ) . into ( ) ,
552
+ )
553
+ }
554
+ #[ pymethod( magic) ]
555
+ fn setstate ( zelf : PyRef < Self > , state : PyObjectRef , vm : & VirtualMachine ) -> PyResult < ( ) > {
556
+ if let Ok ( obj) = ArgIntoBool :: try_from_object ( vm, state) {
557
+ zelf. start_flag . store ( * obj) ;
558
+ }
559
+ Ok ( ( ) )
560
+ }
561
+ }
544
562
impl IterNextIterable for PyItertoolsDropwhile { }
545
563
impl IterNext for PyItertoolsDropwhile {
546
564
fn next ( zelf : & Py < Self > , vm : & VirtualMachine ) -> PyResult < PyIterReturn > {
0 commit comments