Issue #10180: Pickling file objects is now explicitly forbidden, since
unpickling them produced nonsensical results.
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 09ea80f..96fce15 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -952,6 +952,14 @@
return PyBool_FromLong(res);
}
+static PyObject *
+fileio_getstate(fileio *self)
+{
+ PyErr_Format(PyExc_TypeError,
+ "cannot serialize '%s' object", Py_TYPE(self)->tp_name);
+ return NULL;
+}
+
PyDoc_STRVAR(fileio_doc,
"file(name: str[, mode: str]) -> file IO object\n"
@@ -1046,6 +1054,7 @@
{"fileno", (PyCFunction)fileio_fileno, METH_NOARGS, fileno_doc},
{"isatty", (PyCFunction)fileio_isatty, METH_NOARGS, isatty_doc},
{"_dealloc_warn", (PyCFunction)fileio_dealloc_warn, METH_O, NULL},
+ {"__getstate__", (PyCFunction)fileio_getstate, METH_NOARGS, NULL},
{NULL, NULL} /* sentinel */
};