Skip to content

Commit d1d1aa2

Browse files
Use Eduardo's implementation for csv.dialect __reduce__
See: python#16078 This is slightly nicer. Co-authored-by: Eddie Elizondo <[email protected]>
1 parent 8ca3bb3 commit d1d1aa2

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Modules/_csv.c

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

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

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

502504
static struct PyMethodDef dialect_methods[] = {
503-
{"__reduce_ex__", _csv_dialect__reduce_ex__, METH_VARARGS, NULL},
505+
{"__reduce__", Dialect_reduce, METH_VARARGS, dialect_reduce_doc},
506+
{"__reduce_ex__", Dialect_reduce, METH_VARARGS, dialect_reduce_doc},
504507
{NULL, NULL}
505508
};
506509

0 commit comments

Comments
 (0)