mirror of
https://github.com/python/cpython.git
synced 2025-07-19 09:15:34 +00:00
Get rid of the "bozo" __getstate__ that was inserted when __slots__
was used. This simplifies some logic in copy_reg.py (used by pickling). It also broke a test, but this was rewritten to test the new feature. :-)
This commit is contained in:
parent
0c10015a6e
commit
3f50cdc05e
3 changed files with 22 additions and 60 deletions
|
@ -1468,21 +1468,6 @@ static PyGetSetDef subtype_getsets_weakref_only[] = {
|
|||
{0}
|
||||
};
|
||||
|
||||
/* bozo: __getstate__ that raises TypeError */
|
||||
|
||||
static PyObject *
|
||||
bozo_func(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"a class that defines __slots__ without "
|
||||
"defining __getstate__ cannot be pickled");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static PyMethodDef bozo_ml = {"__getstate__", bozo_func, METH_VARARGS};
|
||||
|
||||
static PyObject *bozo_obj = NULL;
|
||||
|
||||
static int
|
||||
valid_identifier(PyObject *s)
|
||||
{
|
||||
|
@ -1740,23 +1725,6 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
|
|||
Py_DECREF(slots);
|
||||
slots = newslots;
|
||||
|
||||
/* See if *this* class defines __getstate__ */
|
||||
if (PyDict_GetItemString(dict, "__getstate__") == NULL) {
|
||||
/* If not, provide a bozo that raises TypeError */
|
||||
if (bozo_obj == NULL) {
|
||||
bozo_obj = PyCFunction_New(&bozo_ml, NULL);
|
||||
if (bozo_obj == NULL)
|
||||
goto bad_slots;
|
||||
}
|
||||
if (PyDict_SetItemString(dict,
|
||||
"__getstate__",
|
||||
bozo_obj) < 0)
|
||||
{
|
||||
Py_DECREF(bozo_obj);
|
||||
goto bad_slots;
|
||||
}
|
||||
}
|
||||
|
||||
/* Secondary bases may provide weakrefs or dict */
|
||||
if (nbases > 1 &&
|
||||
((may_add_dict && !add_dict) ||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue