Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bpo-40077: Re-enable pickle test
  • Loading branch information
corona10 committed Jun 18, 2020
commit fcc972667e81c59fccc36c193d0d0c0f7418f741
4 changes: 1 addition & 3 deletions Lib/test/test_bz2.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,7 @@ def testCompress4G(self, size):
data = None

def testPickle(self):
# Why?
for proto in range(2, pickle.HIGHEST_PROTOCOL + 1):
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
with self.assertRaises(TypeError):
pickle.dumps(BZ2Compressor(), proto)

Expand Down Expand Up @@ -725,7 +724,6 @@ def testDecompress4G(self, size):
decompressed = None

def testPickle(self):
# Why?
for proto in range(2, pickle.HIGHEST_PROTOCOL + 1):
Comment thread
corona10 marked this conversation as resolved.
Outdated
with self.assertRaises(TypeError):
pickle.dumps(BZ2Decompressor(), proto)
Expand Down
36 changes: 35 additions & 1 deletion Modules/_bz2module.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,21 @@ _bz2_BZ2Compressor_flush_impl(BZ2Compressor *self)
return result;
}

/*[clinic input]
_bz2.BZ2Compressor.__reduce__ as _bz2_compressor_reduce

[clinic start generated code]*/

static PyObject *
_bz2_compressor_reduce_impl(BZ2Compressor *self)
/*[clinic end generated code: output=8b4e32a4a405409b input=598cfb30699bd0ee]*/
{
PyErr_Format(PyExc_TypeError,
"cannot pickle %s object",
Py_TYPE(self)->tp_name);
return NULL;
}

static void*
BZ2_Malloc(void* ctx, int items, int size)
{
Expand Down Expand Up @@ -378,13 +393,15 @@ BZ2Compressor_dealloc(BZ2Compressor *self)
static PyMethodDef BZ2Compressor_methods[] = {
_BZ2_BZ2COMPRESSOR_COMPRESS_METHODDEF
_BZ2_BZ2COMPRESSOR_FLUSH_METHODDEF
_BZ2_COMPRESSOR_REDUCE_METHODDEF
{NULL}
};

static PyType_Slot bz2_compressor_type_slots[] = {
{Py_tp_dealloc, BZ2Compressor_dealloc},
{Py_tp_methods, BZ2Compressor_methods},
{Py_tp_init, _bz2_BZ2Compressor___init__},
Comment thread
corona10 marked this conversation as resolved.
{Py_tp_new, PyType_GenericNew},
{Py_tp_doc, (char *)_bz2_BZ2Compressor___init____doc__},
{0, 0}
};
Expand All @@ -396,7 +413,7 @@ static PyType_Spec bz2_compressor_type_spec = {
// dbmtype_spec does not have Py_TPFLAGS_BASETYPE flag
// which prevents to create a subclass.
// So calling PyType_GetModuleState() in this file is always safe.
.flags = Py_TPFLAGS_DEFAULT,
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE,
Comment thread
corona10 marked this conversation as resolved.
Outdated
.slots = bz2_compressor_type_slots,
};

Expand Down Expand Up @@ -618,6 +635,21 @@ _bz2_BZ2Decompressor_decompress_impl(BZ2Decompressor *self, Py_buffer *data,
return result;
}

/*[clinic input]
_bz2.BZ2Decompressor.__reduce__ as _bz2_decompressor_reduce

[clinic start generated code]*/

static PyObject *
_bz2_decompressor_reduce_impl(BZ2Decompressor *self)
/*[clinic end generated code: output=c79772d813bf4271 input=486b9c8c0205e116]*/
{
PyErr_Format(PyExc_TypeError,
"cannot pickle %s object",
Py_TYPE(self)->tp_name);
return NULL;
}

// TODO: Convert it to clinic
Comment thread
corona10 marked this conversation as resolved.
Outdated
static int
_bz2_BZ2Decompressor___init___impl(BZ2Decompressor *self)
Expand Down Expand Up @@ -703,6 +735,7 @@ BZ2Decompressor_dealloc(BZ2Decompressor *self)

static PyMethodDef BZ2Decompressor_methods[] = {
_BZ2_BZ2DECOMPRESSOR_DECOMPRESS_METHODDEF
_BZ2_DECOMPRESSOR_REDUCE_METHODDEF
{NULL}
};

Expand Down Expand Up @@ -731,6 +764,7 @@ static PyType_Slot bz2_decompressor_type_slots[] = {
{Py_tp_init, _bz2_BZ2Decompressor___init__},
{Py_tp_doc, (char *)_bz2_BZ2Decompressor___init____doc__},
{Py_tp_members, BZ2Decompressor_members},
{Py_tp_new, PyType_GenericNew},
{0, 0}
};

Expand Down
36 changes: 35 additions & 1 deletion Modules/clinic/_bz2module.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.