10000 bpo-40077: Re-enable pickle test · python/cpython@fcc9726 · GitHub
[go: up one dir, main page]

Skip to content

Commit fcc9726

Browse files
committed
bpo-40077: Re-enable pickle test
1 parent a45739f commit fcc9726

File tree

3 files changed

+71
-5
lines changed

3 files changed

+71
-5
lines changed

Lib/test/test_bz2.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,7 @@ def testCompress4G(self, size):
666666
data = None
667667

668668
def testPickle(self):
669-
# Why?
670-
for proto in range(2, pickle.HIGHEST_PROTOCOL + 1):
669+
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
671670
with self.assertRaises(TypeError):
672671
pickle.dumps(BZ2Compressor(), proto)
673672

@@ -725,7 +724,6 @@ def testDecompress4G(self, size):
725724
decompressed = None
726725

727726
def testPickle(self):
728-
# Why?
729727
for proto in range(2, pickle.HIGHEST_PROTOCOL + 1):
730728
with self.assertRaises(TypeError):
731729
pickle.dumps(BZ2Decompressor(), proto)

Modules/_bz2module.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,21 @@ _bz2_BZ2Compressor_flush_impl(BZ2Compressor *self)
272272
return result;
273273
}
274274

275+
/*[clinic input]
276+
_bz2.BZ2Compressor.__reduce__ as _bz2_compressor_reduce
277+
278+
[clinic start generated code]*/
279+
280+
static PyObject *
281+
_bz2_compressor_reduce_impl(BZ2Compressor *self)
282+
/*[clinic end generated code: output=8b4e32a4a405409b input=598cfb30699bd0ee]*/
283+
{
284+
PyErr_Format(PyExc_TypeError,
285+
"cannot pickle %s object",
286+
Py_TYPE(self)->tp_name);
287+
return NULL;
288+
}
289+
275290
static void*
276291
BZ2_Malloc(void* ctx, int items, int size)
277292
{
@@ -378,13 +393,15 @@ BZ2Compressor_dealloc(BZ2Compressor *self)
378393
static PyMethodDef BZ2Compressor_methods[] = {
379394
_BZ2_BZ2COMPRESSOR_COMPRESS_METHODDEF
380395
_BZ2_BZ2COMPRESSOR_FLUSH_METHODDEF
396+
_BZ2_COMPRESSOR_REDUCE_METHODDEF
381397
{NULL}
382398
};
383399

384400
static PyType_Slot bz2_compressor_type_slots[] = {
385401
{Py_tp_dealloc, BZ2Compressor_dealloc},
386402
{Py_tp_methods, BZ2Compressor_methods},
387403
{Py_tp_init, _bz2_BZ2Compressor___init__},
404+
{Py_tp_new, PyType_GenericNew},
388405
{Py_tp_doc, (char *)_bz2_BZ2Compressor___init____doc__},
389406
{0, 0}
390407
};
@@ -396,7 +413,7 @@ static PyType_Spec bz2_compressor_type_spec = {
396413
// dbmtype_spec does not have Py_TPFLAGS_BASETYPE flag
397414
// which prevents to create a subclass.
398415
// So calling PyType_GetModuleState() in this file is always safe.
399-
.flags = Py_TPFLAGS_DEFAULT,
416+
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
400417
.slots = bz2_compressor_type_slots,
401418
};
402419

@@ -618,6 +635,21 @@ _bz2_BZ2Decompressor_decompress_impl(BZ2Decompressor *self, Py_buffer *data,
618635
return result;
619636
}
620637

638+
/*[clinic input]
639+
_bz2.BZ2Decompressor.__reduce__ as _bz2_decompressor_reduce
640+
641+
[clinic start generated code]*/
642+
643+
static PyObject *
644+
_bz2_decompressor_reduce_impl(BZ2Decompressor *self)
645+
/*[clinic end generated code: output=c79772d813bf4271 input=486b9c8c0205e116]*/
646+
{
647+
PyErr_Format(PyExc_TypeError,
648+
"cannot pickle %s object",
649+
Py_TYPE(self)->tp_name);
650+
return NULL;
651+
}
652+
621653
// TODO: Convert it to clinic
622654
static int
623655
_bz2_BZ2Decompressor___init___impl(BZ2Decompressor *self)
@@ -703,6 +735,7 @@ BZ2Decompressor_dealloc(BZ2Decompressor *self)
703735

704736
static PyMethodDef BZ2Decompressor_methods[] = {
705737
_BZ2_BZ2DECOMPRESSOR_DECOMPRESS_METHODDEF
738+
_BZ2_DECOMPRESSOR_REDUCE_METHODDEF
706739
{NULL}
707740
};
708741

@@ -731,6 +764,7 @@ static PyType_Slot bz2_decompressor_type_slots[] = {
731764
{Py_tp_init, _bz2_BZ2Decompressor___init__},
732765
{Py_tp_doc, (char *)_bz2_BZ2Decompressor___init____doc__},
733766
{Py_tp_members, BZ2Decompressor_members},
767+
{Py_tp_new, PyType_GenericNew},
734768
{0, 0}
735769
};
736770

Modules/clinic/_bz2module.c.h

Lines changed: 35 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0