Skip to content

Commit e2b5649

Browse files
encukoueduardo-elizondo
authored andcommitted
Use Eduardo's implementation for csv.dialect __reduce__
See: python#16078 This is slightly nicer. Co-authored-by: Eddie Elizondo <eduardo.elizondorueda@gmail.com>
1 parent 820324b commit e2b5649

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

Modules/_csv.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -491,17 +491,20 @@ dialect_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
491491
}
492492

493493
/* Since dialect is now a heap type, it inherits pickling method for
494-
* protocol 0 and 1 from object, therefore it needs to be overrided */
494+
* protocol 0 and 1 from object, therefore it needs to be overriden */
495+
496+
PyDoc_STRVAR(dialect_reduce_doc, "raises an exception to avoid pickling");
495497

496498
static PyObject *
497-
_csv_dialect__reduce_ex__(PyObject *self, PyObject *args) {
498-
PyErr_SetString(PyExc_TypeError,
499-
"Dialect object cannot be pickled.");
499+
Dialect_reduce(PyObject *self, PyObject *args) {
500+
PyErr_Format(PyExc_TypeError,
501+
"cannot pickle '%.100s' instances", _PyType_Name(Py_TYPE(self)));
500502
return NULL;
501503
}
502504

503505
static struct PyMethodDef dialect_methods[] = {
504-
{"__reduce_ex__", _csv_dialect__reduce_ex__, METH_VARARGS, NULL},
506+
{"__reduce__", Dialect_reduce, METH_VARARGS, dialect_reduce_doc},
507+
{"__reduce_ex__", Dialect_reduce, METH_VARARGS, dialect_reduce_doc},
505508
{NULL, NULL}
506509
};
507510

0 commit comments

Comments
 (0)