@@ -19,7 +19,7 @@ mod decl {
1919 identifier,
2020 protocol:: { PyIter , PyIterReturn , PyNumber } ,
2121 raise_if_stop,
22- stdlib:: sys,
22+ stdlib:: { sys, warnings } ,
2323 types:: { Constructor , IterNext , Iterable , Representable , SelfIter } ,
2424 } ;
2525 use crossbeam_utils:: atomic:: AtomicCell ;
@@ -29,6 +29,15 @@ mod decl {
2929 use num_traits:: { Signed , ToPrimitive } ;
3030 use std:: fmt;
3131
32+ fn pickle_deprecation ( vm : & VirtualMachine ) -> PyResult < ( ) > {
33+ warnings:: warn (
34+ vm. ctx . exceptions . deprecation_warning ,
35+ "Itertool pickle/copy/deepcopy support will be removed in a Python 3.14." . to_owned ( ) ,
36+ 1 ,
37+ vm,
38+ )
39+ }
40+
3241 #[ pyattr]
3342 #[ pyclass( name = "chain" ) ]
3443 #[ derive( Debug , PyPayload ) ]
@@ -74,6 +83,7 @@ mod decl {
7483
7584 #[ pymethod]
7685 fn __reduce__ ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyResult < PyTupleRef > {
86+ pickle_deprecation ( vm) ?;
7787 let source = zelf. source . read ( ) . clone ( ) ;
7888 let active = zelf. active . read ( ) . clone ( ) ;
7989 let cls = zelf. class ( ) . to_owned ( ) ;
@@ -204,7 +214,8 @@ mod decl {
204214 #[ pyclass( with( IterNext , Iterable , Constructor ) , flags( BASETYPE ) ) ]
205215 impl PyItertoolsCompress {
206216 #[ pymethod]
207- fn __reduce__ ( zelf : PyRef < Self > ) -> ( PyTypeRef , ( PyIter , PyIter ) ) {
217+ fn __reduce__ ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> ( PyTypeRef , ( PyIter , PyIter ) ) {
218+ let _ = pickle_deprecation ( vm) ;
208219 (
209220 zelf. class ( ) . to_owned ( ) ,
210221 ( zelf. data . clone ( ) , zelf. selectors . clone ( ) ) ,
@@ -274,7 +285,8 @@ mod decl {
274285 // if (lz->cnt == PY_SSIZE_T_MAX)
275286 // return Py_BuildValue("0(00)", Py_TYPE(lz), lz->long_cnt, lz->long_step);
276287 #[ pymethod]
277- fn __reduce__ ( zelf : PyRef < Self > ) -> ( PyTypeRef , ( PyObjectRef , ) ) {
288+ fn __reduce__ ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> ( PyTypeRef , ( PyObjectRef , ) ) {
289+ let _ = pickle_deprecation ( vm) ;
278290 ( zelf. class ( ) . to_owned ( ) , ( zelf. cur . read ( ) . clone ( ) , ) )
279291 }
280292 }
@@ -406,6 +418,7 @@ mod decl {
406418
407419 #[ pymethod]
408420 fn __reduce__ ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyResult < PyTupleRef > {
421+ pickle_deprecation ( vm) ?;
409422 let cls = zelf. class ( ) . to_owned ( ) ;
410423 Ok ( match zelf. times {
411424 Some ( ref times) => vm. new_tuple ( ( cls, ( zelf. object . clone ( ) , * times. read ( ) ) ) ) ,
@@ -474,7 +487,11 @@ mod decl {
474487 #[ pyclass( with( IterNext , Iterable , Constructor ) , flags( BASETYPE ) ) ]
475488 impl PyItertoolsStarmap {
476489 #[ pymethod]
477- fn __reduce__ ( zelf : PyRef < Self > ) -> ( PyTypeRef , ( PyObjectRef , PyIter ) ) {
490+ fn __reduce__ (
491+ zelf : PyRef < Self > ,
492+ vm : & VirtualMachine ,
493+ ) -> ( PyTypeRef , ( PyObjectRef , PyIter ) ) {
494+ let _ = pickle_deprecation ( vm) ;
478495 (
479496 zelf. class ( ) . to_owned ( ) ,
480497 ( zelf. function . clone ( ) , zelf. iterable . clone ( ) ) ,
@@ -539,7 +556,11 @@ mod decl {
539556 #[ pyclass( with( IterNext , Iterable , Constructor ) , flags( BASETYPE ) ) ]
540557 impl PyItertoolsTakewhile {
541558 #[ pymethod]
542- fn __reduce__ ( zelf : PyRef < Self > ) -> ( PyTypeRef , ( PyObjectRef , PyIter ) , u32 ) {
559+ fn __reduce__ (
560+ zelf : PyRef < Self > ,
561+ vm : & VirtualMachine ,
562+ ) -> ( PyTypeRef , ( PyObjectRef , PyIter ) , u32 ) {
563+ let _ = pickle_deprecation ( vm) ;
543564 (
544565 zelf. class ( ) . to_owned ( ) ,
545566 ( zelf. predicate . clone ( ) , zelf. iterable . clone ( ) ) ,
@@ -623,7 +644,11 @@ mod decl {
623644 #[ pyclass( with( IterNext , Iterable , Constructor ) , flags( BASETYPE ) ) ]
624645 impl PyItertoolsDropwhile {
625646 #[ pymethod]
626- fn __reduce__ ( zelf : PyRef < Self > ) -> ( PyTypeRef , ( PyObjectRef , PyIter ) , u32 ) {
647+ fn __reduce__ (
648+ zelf : PyRef < Self > ,
649+ vm : & VirtualMachine ,
650+ ) -> ( PyTypeRef , ( PyObjectRef , PyIter ) , u32 ) {
651+ let _ = pickle_deprecation ( vm) ;
627652 (
628653 zelf. class ( ) . to_owned ( ) ,
629654 ( zelf. predicate . clone ( ) . into ( ) , zelf. iterable . clone ( ) ) ,
@@ -937,6 +962,7 @@ mod decl {
937962
938963 #[ pymethod]
939964 fn __reduce__ ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyResult < PyTupleRef > {
965+ pickle_deprecation ( vm) ?;
940966 let cls = zelf. class ( ) . to_owned ( ) ;
941967 let itr = zelf. iterable . clone ( ) ;
942968 let cur = zelf. cur . take ( ) ;
@@ -1032,7 +1058,11 @@ mod decl {
10321058 #[ pyclass( with( IterNext , Iterable , Constructor ) , flags( BASETYPE ) ) ]
10331059 impl PyItertoolsFilterFalse {
10341060 #[ pymethod]
1035- fn __reduce__ ( zelf : PyRef < Self > ) -> ( PyTypeRef , ( PyObjectRef , PyIter ) ) {
1061+ fn __reduce__ (
1062+ zelf : PyRef < Self > ,
1063+ vm : & VirtualMachine ,
1064+ ) -> ( PyTypeRef , ( PyObjectRef , PyIter ) ) {
1065+ let _ = pickle_deprecation ( vm) ;
10361066 (
10371067 zelf. class ( ) . to_owned ( ) ,
10381068 ( zelf. predicate . clone ( ) , zelf. iterable . clone ( ) ) ,
@@ -1110,6 +1140,7 @@ mod decl {
11101140
11111141 #[ pymethod]
11121142 fn __reduce__ ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyTupleRef {
1143+ let _ = pickle_deprecation ( vm) ;
11131144 let class = zelf. class ( ) . to_owned ( ) ;
11141145 let bin_op = zelf. bin_op . clone ( ) ;
11151146 let it = zelf. iterable . clone ( ) ;
@@ -1374,6 +1405,7 @@ mod decl {
13741405
13751406 #[ pymethod]
13761407 fn __reduce__ ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyTupleRef {
1408+ let _ = pickle_deprecation ( vm) ;
13771409 let class = zelf. class ( ) . to_owned ( ) ;
13781410
13791411 if zelf. stop . load ( ) {
@@ -1483,6 +1515,7 @@ mod decl {
14831515 impl PyItertoolsCombinations {
14841516 #[ pymethod]
14851517 fn __reduce__ ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyTupleRef {
1518+ let _ = pickle_deprecation ( vm) ;
14861519 let r = zelf. r . load ( ) ;
14871520
14881521 let class = zelf. class ( ) . to_owned ( ) ;
@@ -1724,6 +1757,7 @@ mod decl {
17241757 impl PyItertoolsPermutations {
17251758 #[ pymethod]
17261759 fn __reduce__ ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyRef < PyTuple > {
1760+ let _ = pickle_deprecation ( vm) ;
17271761 vm. new_tuple ( (
17281762 zelf. class ( ) . to_owned ( ) ,
17291763 vm. new_tuple ( ( zelf. pool . clone ( ) , vm. ctx . new_int ( zelf. r . load ( ) ) ) ) ,
@@ -1837,6 +1871,7 @@ mod decl {
18371871 impl PyItertoolsZipLongest {
18381872 #[ pymethod]
18391873 fn __reduce__ ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyResult < PyTupleRef > {
1874+ pickle_deprecation ( vm) ?;
18401875 let args: Vec < PyObjectRef > = zelf
18411876 . iterators
18421877 . iter ( )
0 commit comments