@@ -19,7 +19,7 @@ mod decl {
19
19
identifier,
20
20
protocol:: { PyIter , PyIterReturn , PyNumber } ,
21
21
raise_if_stop,
22
- stdlib:: sys,
22
+ stdlib:: { sys, warnings } ,
23
23
types:: { Constructor , IterNext , Iterable , Representable , SelfIter } ,
24
24
} ;
25
25
use crossbeam_utils:: atomic:: AtomicCell ;
@@ -29,6 +29,15 @@ mod decl {
29
29
use num_traits:: { Signed , ToPrimitive } ;
30
30
use std:: fmt;
31
31
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
+
32
41
#[ pyattr]
33
42
#[ pyclass( name = "chain" ) ]
34
43
#[ derive( Debug , PyPayload ) ]
@@ -74,6 +83,7 @@ mod decl {
74
83
75
84
#[ pymethod]
76
85
fn __reduce__ ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyResult < PyTupleRef > {
86
+ pickle_deprecation ( vm) ?;
77
87
let source = zelf. source . read ( ) . clone ( ) ;
78
88
let active = zelf. active . read ( ) . clone ( ) ;
79
89
let cls = zelf. class ( ) . to_owned ( ) ;
@@ -204,7 +214,8 @@ mod decl {
204
214
#[ pyclass( with( IterNext , Iterable , Constructor ) , flags( BASETYPE ) ) ]
205
215
impl PyItertoolsCompress {
206
216
#[ 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) ;
208
219
(
209
220
zelf. class ( ) . to_owned ( ) ,
210
221
( zelf. data . clone ( ) , zelf. selectors . clone ( ) ) ,
@@ -274,7 +285,8 @@ mod decl {
274
285
// if (lz->cnt == PY_SSIZE_T_MAX)
275
286
// return Py_BuildValue("0(00)", Py_TYPE(lz), lz->long_cnt, lz->long_step);
276
287
#[ pymethod]
277
- fn __reduce__ ( zelf : PyRef < Self > ) -> ( PyTypeRef , ( PyObjectRef , ) ) {
288
+ fn __reduce__ ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> ( PyTypeRef , ( PyObjectRef , ) ) {
289
+ let _ = pickle_deprecation ( vm) ;
278
290
( zelf. class ( ) . to_owned ( ) , ( zelf. cur . read ( ) . clone ( ) , ) )
279
291
}
280
292
}
@@ -406,6 +418,7 @@ mod decl {
406
418
407
419
#[ pymethod]
408
420
fn __reduce__ ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyResult < PyTupleRef > {
421
+ pickle_deprecation ( vm) ?;
409
422
let cls = zelf. class ( ) . to_owned ( ) ;
410
423
Ok ( match zelf. times {
411
424
Some ( ref times) => vm. new_tuple ( ( cls, ( zelf. object . clone ( ) , * times. read ( ) ) ) ) ,
@@ -474,7 +487,11 @@ mod decl {
474
487
#[ pyclass( with( IterNext , Iterable , Constructor ) , flags( BASETYPE ) ) ]
475
488
impl PyItertoolsStarmap {
476
489
#[ 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) ;
478
495
(
479
496
zelf. class ( ) . to_owned ( ) ,
480
497
( zelf. function . clone ( ) , zelf. iterable . clone ( ) ) ,
@@ -539,7 +556,11 @@ mod decl {
539
556
#[ pyclass( with( IterNext , Iterable , Constructor ) , flags( BASETYPE ) ) ]
540
557
impl PyItertoolsTakewhile {
541
558
#[ 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) ;
543
564
(
544
565
zelf. class ( ) . to_owned ( ) ,
545
566
( zelf. predicate . clone ( ) , zelf. iterable . clone ( ) ) ,
@@ -623,7 +644,11 @@ mod decl {
623
644
#[ pyclass( with( IterNext , Iterable , Constructor ) , flags( BASETYPE ) ) ]
624
645
impl PyItertoolsDropwhile {
625
646
#[ 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) ;
627
652
(
628
653
zelf. class ( ) . to_owned ( ) ,
629
654
( zelf. predicate . clone ( ) . into ( ) , zelf. iterable . clone ( ) ) ,
@@ -937,6 +962,7 @@ mod decl {
937
962
938
963
#[ pymethod]
939
964
fn __reduce__ ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyResult < PyTupleRef > {
965
+ pickle_deprecation ( vm) ?;
940
966
let cls = zelf. class ( ) . to_owned ( ) ;
941
967
let itr = zelf. iterable . clone ( ) ;
942
968
let cur = zelf. cur . take ( ) ;
@@ -1032,7 +1058,11 @@ mod decl {
1032
1058
#[ pyclass( with( IterNext , Iterable , Constructor ) , flags( BASETYPE ) ) ]
1033
1059
impl PyItertoolsFilterFalse {
1034
1060
#[ 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) ;
1036
1066
(
1037
1067
zelf. class ( ) . to_owned ( ) ,
1038
1068
( zelf. predicate . clone ( ) , zelf. iterable . clone ( ) ) ,
@@ -1110,6 +1140,7 @@ mod decl {
1110
1140
1111
1141
#[ pymethod]
1112
1142
fn __reduce__ ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyTupleRef {
1143
+ let _ = pickle_deprecation ( vm) ;
1113
1144
let class = zelf. class ( ) . to_owned ( ) ;
1114
1145
let bin_op = zelf. bin_op . clone ( ) ;
1115
1146
let it = zelf. iterable . clone ( ) ;
@@ -1374,6 +1405,7 @@ mod decl {
1374
1405
1375
1406
#[ pymethod]
1376
1407
fn __reduce__ ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyTupleRef {
1408
+ let _ = pickle_deprecation ( vm) ;
1377
1409
let class = zelf. class ( ) . to_owned ( ) ;
1378
1410
1379
1411
if zelf. stop . load ( ) {
@@ -1483,6 +1515,7 @@ mod decl {
1483
1515
impl PyItertoolsCombinations {
1484
1516
#[ pymethod]
1485
1517
fn __reduce__ ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyTupleRef {
1518
+ let _ = pickle_deprecation ( vm) ;
1486
1519
let r = zelf. r . load ( ) ;
1487
1520
1488
1521
let class = zelf. class ( ) . to_owned ( ) ;
@@ -1724,6 +1757,7 @@ mod decl {
1724
1757
impl PyItertoolsPermutations {
1725
1758
#[ pymethod]
1726
1759
fn __reduce__ ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyRef < PyTuple > {
1760
+ let _ = pickle_deprecation ( vm) ;
1727
1761
vm. new_tuple ( (
1728
1762
zelf. class ( ) . to_owned ( ) ,
1729
1763
vm. new_tuple ( ( zelf. pool . clone ( ) , vm. ctx . new_int ( zelf. r . load ( ) ) ) ) ,
@@ -1837,6 +1871,7 @@ mod decl {
1837
1871
impl PyItertoolsZipLongest {
1838
1872
#[ pymethod]
1839
1873
fn __reduce__ ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyResult < PyTupleRef > {
1874
+ pickle_deprecation ( vm) ?;
1840
1875
let args: Vec < PyObjectRef > = zelf
1841
1876
. iterators
1842
1877
. iter ( )
0 commit comments