return self.raw.mode
def __getstate__(self):
- raise TypeError("can not serialize a '{0}' object"
- .format(self.__class__.__name__))
+ raise TypeError(f"cannot pickle {self.__class__.__name__!r} object")
def __repr__(self):
modname = self.__class__.__module__
self.close()
def __getstate__(self):
- raise TypeError("cannot serialize '%s' object", self.__class__.__name__)
+ raise TypeError(f"cannot pickle {self.__class__.__name__!r} object")
def __repr__(self):
class_name = '%s.%s' % (self.__class__.__module__,
def _reduce_ex(self, proto):
assert proto < 2
- for base in self.__class__.__mro__:
+ cls = self.__class__
+ for base in cls.__mro__:
if hasattr(base, '__flags__') and not base.__flags__ & _HEAPTYPE:
break
else:
if base is object:
state = None
else:
- if base is self.__class__:
- raise TypeError("can't pickle %s objects" % base.__name__)
+ if base is cls:
+ raise TypeError(f"cannot pickle {cls.__name__!r} object")
state = base(self)
- args = (self.__class__, base, state)
+ args = (cls, base, state)
try:
getstate = self.__getstate__
except AttributeError:
if getattr(self, "__slots__", None):
- raise TypeError("a class that defines __slots__ without "
- "defining __getstate__ cannot be pickled") from None
+ raise TypeError(f"cannot pickle {cls.__name__!r} object: "
+ f"a class that defines __slots__ without "
+ f"defining __getstate__ cannot be pickled "
+ f"with protocol {proto}") from None
try:
dict = self.__dict__
except AttributeError:
return s
def __getstate__(self):
- raise TypeError("Cannot serialize socket object")
+ raise TypeError(f"cannot pickle {self.__class__.__name__!r} object")
def dup(self):
"""dup() -> socket object
--- /dev/null
+Changed standard error message for non-pickleable and non-copyable types. It
+now says "cannot pickle" instead of "can't pickle" or "cannot serialize".
return result;
}
-static PyObject *
-BZ2Compressor_getstate(BZ2Compressor *self, PyObject *noargs)
-{
- PyErr_Format(PyExc_TypeError, "cannot serialize '%s' object",
- Py_TYPE(self)->tp_name);
- return NULL;
-}
-
static void*
BZ2_Malloc(void* ctx, int items, int size)
{
static PyMethodDef BZ2Compressor_methods[] = {
_BZ2_BZ2COMPRESSOR_COMPRESS_METHODDEF
_BZ2_BZ2COMPRESSOR_FLUSH_METHODDEF
- {"__getstate__", (PyCFunction)BZ2Compressor_getstate, METH_NOARGS},
{NULL}
};
return result;
}
-static PyObject *
-BZ2Decompressor_getstate(BZ2Decompressor *self, PyObject *noargs)
-{
- PyErr_Format(PyExc_TypeError, "cannot serialize '%s' object",
- Py_TYPE(self)->tp_name);
- return NULL;
-}
-
/*[clinic input]
_bz2.BZ2Decompressor.__init__
static PyMethodDef BZ2Decompressor_methods[] = {
_BZ2_BZ2DECOMPRESSOR_DECOMPRESS_METHODDEF
- {"__getstate__", (PyCFunction)BZ2Decompressor_getstate, METH_NOARGS},
{NULL}
};
return PyObject_CallMethodObjArgs(self->raw, _PyIO_str_isatty, NULL);
}
-/* Serialization */
-
-static PyObject *
-buffered_getstate(buffered *self, PyObject *Py_UNUSED(ignored))
-{
- PyErr_Format(PyExc_TypeError,
- "cannot serialize '%s' object", Py_TYPE(self)->tp_name);
- return NULL;
-}
-
/* Forward decls */
static PyObject *
_bufferedwriter_flush_unlocked(buffered *);
{"fileno", (PyCFunction)buffered_fileno, METH_NOARGS},
{"isatty", (PyCFunction)buffered_isatty, METH_NOARGS},
{"_dealloc_warn", (PyCFunction)buffered_dealloc_warn, METH_O},
- {"__getstate__", (PyCFunction)buffered_getstate, METH_NOARGS},
_IO__BUFFERED_READ_METHODDEF
_IO__BUFFERED_PEEK_METHODDEF
{"fileno", (PyCFunction)buffered_fileno, METH_NOARGS},
{"isatty", (PyCFunction)buffered_isatty, METH_NOARGS},
{"_dealloc_warn", (PyCFunction)buffered_dealloc_warn, METH_O},
- {"__getstate__", (PyCFunction)buffered_getstate, METH_NOARGS},
_IO_BUFFEREDWRITER_WRITE_METHODDEF
_IO__BUFFERED_TRUNCATE_METHODDEF
{"close", (PyCFunction)bufferedrwpair_close, METH_NOARGS},
{"isatty", (PyCFunction)bufferedrwpair_isatty, METH_NOARGS},
- {"__getstate__", (PyCFunction)buffered_getstate, METH_NOARGS},
-
{NULL, NULL}
};
{"fileno", (PyCFunction)buffered_fileno, METH_NOARGS},
{"isatty", (PyCFunction)buffered_isatty, METH_NOARGS},
{"_dealloc_warn", (PyCFunction)buffered_dealloc_warn, METH_O},
- {"__getstate__", (PyCFunction)buffered_getstate, METH_NOARGS},
{"flush", (PyCFunction)buffered_flush, METH_NOARGS},
return PyBool_FromLong(res);
}
-static PyObject *
-fileio_getstate(fileio *self, PyObject *Py_UNUSED(ignored))
-{
- PyErr_Format(PyExc_TypeError,
- "cannot serialize '%s' object", Py_TYPE(self)->tp_name);
- return NULL;
-}
-
#include "clinic/fileio.c.h"
static PyMethodDef fileio_methods[] = {
_IO_FILEIO_FILENO_METHODDEF
_IO_FILEIO_ISATTY_METHODDEF
{"_dealloc_warn", (PyCFunction)fileio_dealloc_warn, METH_O, NULL},
- {"__getstate__", (PyCFunction)fileio_getstate, METH_NOARGS, NULL},
{NULL, NULL} /* sentinel */
};
return _PyObject_CallMethodId(self->buffer, &PyId_isatty, NULL);
}
-static PyObject *
-textiowrapper_getstate(textio *self, PyObject *args)
-{
- PyErr_Format(PyExc_TypeError,
- "cannot serialize '%s' object", Py_TYPE(self)->tp_name);
- return NULL;
-}
-
/*[clinic input]
_io.TextIOWrapper.flush
[clinic start generated code]*/
_IO_TEXTIOWRAPPER_READABLE_METHODDEF
_IO_TEXTIOWRAPPER_WRITABLE_METHODDEF
_IO_TEXTIOWRAPPER_ISATTY_METHODDEF
- {"__getstate__", (PyCFunction)textiowrapper_getstate, METH_NOARGS},
_IO_TEXTIOWRAPPER_SEEK_METHODDEF
_IO_TEXTIOWRAPPER_TELL_METHODDEF
Py_RETURN_TRUE;
}
-static PyObject *
-winconsoleio_getstate(winconsoleio *self, PyObject *Py_UNUSED(ignored))
-{
- PyErr_Format(PyExc_TypeError,
- "cannot serialize '%s' object", Py_TYPE(self)->tp_name);
- return NULL;
-}
-
#include "clinic/winconsoleio.c.h"
static PyMethodDef winconsoleio_methods[] = {
_IO__WINDOWSCONSOLEIO_WRITABLE_METHODDEF
_IO__WINDOWSCONSOLEIO_FILENO_METHODDEF
_IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
- {"__getstate__", (PyCFunction)winconsoleio_getstate, METH_NOARGS, NULL},
{NULL, NULL} /* sentinel */
};
return result;
}
-static PyObject *
-Compressor_getstate(Compressor *self, PyObject *noargs)
-{
- PyErr_Format(PyExc_TypeError, "cannot serialize '%s' object",
- Py_TYPE(self)->tp_name);
- return NULL;
-}
-
static int
Compressor_init_xz(lzma_stream *lzs, int check, uint32_t preset,
PyObject *filterspecs)
static PyMethodDef Compressor_methods[] = {
_LZMA_LZMACOMPRESSOR_COMPRESS_METHODDEF
_LZMA_LZMACOMPRESSOR_FLUSH_METHODDEF
- {"__getstate__", (PyCFunction)Compressor_getstate, METH_NOARGS},
{NULL}
};
return result;
}
-static PyObject *
-Decompressor_getstate(Decompressor *self, PyObject *noargs)
-{
- PyErr_Format(PyExc_TypeError, "cannot serialize '%s' object",
- Py_TYPE(self)->tp_name);
- return NULL;
-}
-
static int
Decompressor_init_raw(lzma_stream *lzs, PyObject *filterspecs)
{
static PyMethodDef Decompressor_methods[] = {
_LZMA_LZMADECOMPRESSOR_DECOMPRESS_METHODDEF
- {"__getstate__", (PyCFunction)Decompressor_getstate, METH_NOARGS},
{NULL}
};
if (required && obj->ob_type->tp_itemsize) {
PyErr_Format(PyExc_TypeError,
- "can't pickle %.200s objects",
+ "cannot pickle '%.200s' object",
Py_TYPE(obj)->tp_name);
return NULL;
}
Py_DECREF(slotnames);
Py_DECREF(state);
PyErr_Format(PyExc_TypeError,
- "can't pickle %.200s objects",
+ "cannot pickle '%.200s' object",
Py_TYPE(obj)->tp_name);
return NULL;
}
if (Py_TYPE(obj)->tp_new == NULL) {
PyErr_Format(PyExc_TypeError,
- "can't pickle %.200s objects",
+ "cannot pickle '%.200s' object",
Py_TYPE(obj)->tp_name);
return NULL;
}