summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-05-26 21:02:42 (GMT)
committerGitHub <noreply@github.com>2023-05-26 21:02:42 (GMT)
commit05189f3054e3a831967a1bb53d14d97c97e31598 (patch)
tree274c61c7414e155104c18c754ee6cfbbfe90c21e /Modules
parent305d78b71481e309051b1b88f363805d8c0ad34a (diff)
downloadcpython-05189f3054e3a831967a1bb53d14d97c97e31598.zip
cpython-05189f3054e3a831967a1bb53d14d97c97e31598.tar.gz
cpython-05189f3054e3a831967a1bb53d14d97c97e31598.tar.bz2
[3.12] GH-101588: Deprecate pickle/copy/deepcopy support in itertools (GH-104965) (GH-104997)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/itertoolsmodule.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 555eab0..4a6d131 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -93,6 +93,16 @@ class itertools.pairwise "pairwiseobject *" "clinic_state()->pairwise_type"
#undef clinic_state_by_cls
#undef clinic_state
+/* Deprecation of pickle support: GH-101588 *********************************/
+
+#define ITERTOOL_PICKLE_DEPRECATION \
+ if (PyErr_WarnEx( \
+ PyExc_DeprecationWarning, \
+ "Itertool pickle/copy/deepcopy support " \
+ "will be removed in a Python 3.14.", 1) < 0) { \
+ return NULL; \
+ }
+
/* batched object ************************************************************/
/* Note: The built-in zip() function includes a "strict" argument
@@ -506,6 +516,7 @@ groupby_reduce(groupbyobject *lz, PyObject *Py_UNUSED(ignored))
/* reduce as a 'new' call with an optional 'setstate' if groupby
* has started
*/
+ ITERTOOL_PICKLE_DEPRECATION;
PyObject *value;
if (lz->tgtkey && lz->currkey && lz->currvalue)
value = Py_BuildValue("O(OO)(OOO)", Py_TYPE(lz),
@@ -522,6 +533,7 @@ PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
static PyObject *
groupby_setstate(groupbyobject *lz, PyObject *state)
{
+ ITERTOOL_PICKLE_DEPRECATION;
PyObject *currkey, *currvalue, *tgtkey;
if (!PyTuple_Check(state)) {
PyErr_SetString(PyExc_TypeError, "state is not a tuple");
@@ -660,6 +672,7 @@ _grouper_next(_grouperobject *igo)
static PyObject *
_grouper_reduce(_grouperobject *lz, PyObject *Py_UNUSED(ignored))
{
+ ITERTOOL_PICKLE_DEPRECATION;
if (((groupbyobject *)lz->parent)->currgrouper != lz) {
return Py_BuildValue("N(())", _PyEval_GetBuiltin(&_Py_ID(iter)));
}
@@ -828,6 +841,7 @@ teedataobject_dealloc(teedataobject *tdo)
static PyObject *
teedataobject_reduce(teedataobject *tdo, PyObject *Py_UNUSED(ignored))
{
+ ITERTOOL_PICKLE_DEPRECATION;
int i;
/* create a temporary list of already iterated values */
PyObject *values = PyList_New(tdo->numread);
@@ -1041,12 +1055,14 @@ tee_dealloc(teeobject *to)
static PyObject *
tee_reduce(teeobject *to, PyObject *Py_UNUSED(ignored))
{
+ ITERTOOL_PICKLE_DEPRECATION;
return Py_BuildValue("O(())(Oi)", Py_TYPE(to), to->dataobj, to->index);
}
static PyObject *
tee_setstate(teeobject *to, PyObject *state)
{
+ ITERTOOL_PICKLE_DEPRECATION;
teedataobject *tdo;
int index;
if (!PyTuple_Check(state)) {
@@ -1275,6 +1291,7 @@ cycle_next(cycleobject *lz)
static PyObject *
cycle_reduce(cycleobject *lz, PyObject *Py_UNUSED(ignored))
{
+ ITERTOOL_PICKLE_DEPRECATION;
/* Create a new cycle with the iterator tuple, then set the saved state */
if (lz->it == NULL) {
PyObject *it = PyObject_GetIter(lz->saved);
@@ -1298,6 +1315,7 @@ cycle_reduce(cycleobject *lz, PyObject *Py_UNUSED(ignored))
static PyObject *
cycle_setstate(cycleobject *lz, PyObject *state)
{
+ ITERTOOL_PICKLE_DEPRECATION;
PyObject *saved=NULL;
int firstpass;
if (!PyTuple_Check(state)) {
@@ -1446,12 +1464,14 @@ dropwhile_next(dropwhileobject *lz)
static PyObject *
dropwhile_reduce(dropwhileobject *lz, PyObject *Py_UNUSED(ignored))
{
+ ITERTOOL_PICKLE_DEPRECATION;
return Py_BuildValue("O(OO)l", Py_TYPE(lz), lz->func, lz->it, lz->start);
}
static PyObject *
dropwhile_setstate(dropwhileobject *lz, PyObject *state)
{
+ ITERTOOL_PICKLE_DEPRECATION;
int start = PyObject_IsTrue(state);
if (start < 0)
return NULL;
@@ -1584,12 +1604,14 @@ takewhile_next(takewhileobject *lz)
static PyObject *
takewhile_reduce(takewhileobject *lz, PyObject *Py_UNUSED(ignored))
{
+ ITERTOOL_PICKLE_DEPRECATION;
return Py_BuildValue("O(OO)l", Py_TYPE(lz), lz->func, lz->it, lz->stop);
}
static PyObject *
takewhile_reduce_setstate(takewhileobject *lz, PyObject *state)
{
+ ITERTOOL_PICKLE_DEPRECATION;
int stop = PyObject_IsTrue(state);
if (stop < 0)
@@ -1786,6 +1808,7 @@ empty:
static PyObject *
islice_reduce(isliceobject *lz, PyObject *Py_UNUSED(ignored))
{
+ ITERTOOL_PICKLE_DEPRECATION;
/* When unpickled, generate a new object with the same bounds,
* then 'setstate' with the next and count
*/
@@ -1818,6 +1841,7 @@ islice_reduce(isliceobject *lz, PyObject *Py_UNUSED(ignored))
static PyObject *
islice_setstate(isliceobject *lz, PyObject *state)
{
+ ITERTOOL_PICKLE_DEPRECATION;
Py_ssize_t cnt = PyLong_AsSsize_t(state);
if (cnt == -1 && PyErr_Occurred())
@@ -1953,6 +1977,7 @@ starmap_next(starmapobject *lz)
static PyObject *
starmap_reduce(starmapobject *lz, PyObject *Py_UNUSED(ignored))
{
+ ITERTOOL_PICKLE_DEPRECATION;
/* Just pickle the iterator */
return Py_BuildValue("O(OO)", Py_TYPE(lz), lz->func, lz->it);
}
@@ -2109,6 +2134,7 @@ chain_next(chainobject *lz)
static PyObject *
chain_reduce(chainobject *lz, PyObject *Py_UNUSED(ignored))
{
+ ITERTOOL_PICKLE_DEPRECATION;
if (lz->source) {
/* we can't pickle function objects (itertools.from_iterable) so
* we must use setstate to replace the iterable. One day we
@@ -2128,6 +2154,7 @@ chain_reduce(chainobject *lz, PyObject *Py_UNUSED(ignored))
static PyObject *
chain_setstate(chainobject *lz, PyObject *state)
{
+ ITERTOOL_PICKLE_DEPRECATION;
PyObject *source, *active=NULL;
if (!PyTuple_Check(state)) {
@@ -2403,6 +2430,7 @@ empty:
static PyObject *
product_reduce(productobject *lz, PyObject *Py_UNUSED(ignored))
{
+ ITERTOOL_PICKLE_DEPRECATION;
if (lz->stopped) {
return Py_BuildValue("O(())", Py_TYPE(lz));
} else if (lz->result == NULL) {
@@ -2433,6 +2461,7 @@ product_reduce(productobject *lz, PyObject *Py_UNUSED(ignored))
static PyObject *
product_setstate(productobject *lz, PyObject *state)
{
+ ITERTOOL_PICKLE_DEPRECATION;
PyObject *result;
Py_ssize_t n, i;
@@ -2711,6 +2740,7 @@ empty:
static PyObject *
combinations_reduce(combinationsobject *lz, PyObject *Py_UNUSED(ignored))
{
+ ITERTOOL_PICKLE_DEPRECATION;
if (lz->result == NULL) {
return Py_BuildValue("O(On)", Py_TYPE(lz), lz->pool, lz->r);
} else if (lz->stopped) {
@@ -2740,6 +2770,7 @@ combinations_reduce(combinationsobject *lz, PyObject *Py_UNUSED(ignored))
static PyObject *
combinations_setstate(combinationsobject *lz, PyObject *state)
{
+ ITERTOOL_PICKLE_DEPRECATION;
PyObject *result;
Py_ssize_t i;
Py_ssize_t n = PyTuple_GET_SIZE(lz->pool);
@@ -3019,6 +3050,7 @@ empty:
static PyObject *
cwr_reduce(cwrobject *lz, PyObject *Py_UNUSED(ignored))
{
+ ITERTOOL_PICKLE_DEPRECATION;
if (lz->result == NULL) {
return Py_BuildValue("O(On)", Py_TYPE(lz), lz->pool, lz->r);
} else if (lz->stopped) {
@@ -3047,6 +3079,7 @@ cwr_reduce(cwrobject *lz, PyObject *Py_UNUSED(ignored))
static PyObject *
cwr_setstate(cwrobject *lz, PyObject *state)
{
+ ITERTOOL_PICKLE_DEPRECATION;
PyObject *result;
Py_ssize_t n, i;
@@ -3354,6 +3387,7 @@ empty:
static PyObject *
permutations_reduce(permutationsobject *po, PyObject *Py_UNUSED(ignored))
{
+ ITERTOOL_PICKLE_DEPRECATION;
if (po->result == NULL) {
return Py_BuildValue("O(On)", Py_TYPE(po), po->pool, po->r);
} else if (po->stopped) {
@@ -3396,6 +3430,7 @@ permutations_reduce(permutationsobject *po, PyObject *Py_UNUSED(ignored))
static PyObject *
permutations_setstate(permutationsobject *po, PyObject *state)
{
+ ITERTOOL_PICKLE_DEPRECATION;
PyObject *indices, *cycles, *result;
Py_ssize_t n, i;
@@ -3593,6 +3628,7 @@ accumulate_next(accumulateobject *lz)
static PyObject *
accumulate_reduce(accumulateobject *lz, PyObject *Py_UNUSED(ignored))
{
+ ITERTOOL_PICKLE_DEPRECATION;
itertools_state *state = lz->state;
if (lz->initial != Py_None) {
@@ -3628,6 +3664,7 @@ accumulate_reduce(accumulateobject *lz, PyObject *Py_UNUSED(ignored))
static PyObject *
accumulate_setstate(accumulateobject *lz, PyObject *state)
{
+ ITERTOOL_PICKLE_DEPRECATION;
Py_INCREF(state);
Py_XSETREF(lz->total, state);
Py_RETURN_NONE;
@@ -3776,6 +3813,7 @@ compress_next(compressobject *lz)
static PyObject *
compress_reduce(compressobject *lz, PyObject *Py_UNUSED(ignored))
{
+ ITERTOOL_PICKLE_DEPRECATION;
return Py_BuildValue("O(OO)", Py_TYPE(lz),
lz->data, lz->selectors);
}
@@ -3908,6 +3946,7 @@ filterfalse_next(filterfalseobject *lz)
static PyObject *
filterfalse_reduce(filterfalseobject *lz, PyObject *Py_UNUSED(ignored))
{
+ ITERTOOL_PICKLE_DEPRECATION;
return Py_BuildValue("O(OO)", Py_TYPE(lz), lz->func, lz->it);
}
@@ -4135,6 +4174,7 @@ count_repr(countobject *lz)
static PyObject *
count_reduce(countobject *lz, PyObject *Py_UNUSED(ignored))
{
+ ITERTOOL_PICKLE_DEPRECATION;
if (lz->cnt == PY_SSIZE_T_MAX)
return Py_BuildValue("O(OO)", Py_TYPE(lz), lz->long_cnt, lz->long_step);
return Py_BuildValue("O(n)", Py_TYPE(lz), lz->cnt);
@@ -4258,6 +4298,7 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(
static PyObject *
repeat_reduce(repeatobject *ro, PyObject *Py_UNUSED(ignored))
{
+ ITERTOOL_PICKLE_DEPRECATION;
/* unpickle this so that a new repeat iterator is constructed with an
* object, then call __setstate__ on it to set cnt
*/
@@ -4478,7 +4519,7 @@ zip_longest_next(ziplongestobject *lz)
static PyObject *
zip_longest_reduce(ziplongestobject *lz, PyObject *Py_UNUSED(ignored))
{
-
+ ITERTOOL_PICKLE_DEPRECATION;
/* Create a new tuple with empty sequences where appropriate to pickle.
* Then use setstate to set the fillvalue
*/
@@ -4505,6 +4546,7 @@ zip_longest_reduce(ziplongestobject *lz, PyObject *Py_UNUSED(ignored))
static PyObject *
zip_longest_setstate(ziplongestobject *lz, PyObject *state)
{
+ ITERTOOL_PICKLE_DEPRECATION;
Py_INCREF(state);
Py_XSETREF(lz->fillvalue, state);
Py_RETURN_NONE;