There's no good reason for datetime objects to expose __getstate__()

anymore either, so don't.  This also allows to get rid of obscure code
making __getnewargs__ identical to __getstate__ (hmm ... hope there
wasn't more to this than I realize!).
This commit is contained in:
Tim Peters 2003-02-01 02:54:15 +00:00
parent 874d9bcbe5
commit b57f8f02ba
3 changed files with 6 additions and 66 deletions

View File

@ -278,8 +278,6 @@ class TestTimeDelta(unittest.TestCase):
def test_pickling(self):
args = 12, 34, 56
orig = timedelta(*args)
state = orig.__getstate__()
self.assertEqual(args, state)
for pickler, unpickler, proto in pickle_choices:
green = pickler.dumps(orig, proto)
derived = unpickler.loads(green)
@ -832,8 +830,6 @@ class TestDate(unittest.TestCase):
def test_pickling(self):
args = 6, 7, 23
orig = self.theclass(*args)
state = orig.__getstate__()
self.assertEqual(state, ('\x00\x06\x07\x17',), self.theclass)
for pickler, unpickler, proto in pickle_choices:
green = pickler.dumps(orig, proto)
derived = unpickler.loads(green)
@ -1186,8 +1182,6 @@ class TestDateTime(TestDate):
def test_pickling(self):
args = 6, 7, 23, 20, 59, 1, 64**2
orig = self.theclass(*args)
state = orig.__getstate__()
self.assertEqual(state, ('\x00\x06\x07\x17\x14\x3b\x01\x00\x10\x00',))
for pickler, unpickler, proto in pickle_choices:
green = pickler.dumps(orig, proto)
derived = unpickler.loads(green)
@ -1567,8 +1561,6 @@ class TestTime(unittest.TestCase):
def test_pickling(self):
args = 20, 59, 16, 64**2
orig = self.theclass(*args)
state = orig.__getstate__()
self.assertEqual(state, ('\x14\x3b\x10\x00\x10\x00',))
for pickler, unpickler, proto in pickle_choices:
green = pickler.dumps(orig, proto)
derived = unpickler.loads(green)
@ -1877,8 +1869,6 @@ class TestTimeTZ(TestTime, TZInfoBase):
# Try one without a tzinfo.
args = 20, 59, 16, 64**2
orig = self.theclass(*args)
state = orig.__getstate__()
self.assertEqual(state, ('\x14\x3b\x10\x00\x10\x00',))
for pickler, unpickler, proto in pickle_choices:
green = pickler.dumps(orig, proto)
derived = unpickler.loads(green)
@ -2080,8 +2070,6 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase):
# Try one without a tzinfo.
args = 6, 7, 23, 20, 59, 1, 64**2
orig = self.theclass(*args)
state = orig.__getstate__()
self.assertEqual(state, ('\x00\x06\x07\x17\x14\x3b\x01\x00\x10\x00',))
for pickler, unpickler, proto in pickle_choices:
green = pickler.dumps(orig, proto)
derived = unpickler.loads(green)

View File

@ -131,8 +131,8 @@ Extension modules
The pickle format of date, time and datetime objects has changed
completely. The undocumented pickler and unpickler functions no
longer exist. The undocumented __setstate__() methods no longer
exist either.
longer exist. The undocumented __setstate__() and __getstate__()
methods no longer exist either.
Library
-------

View File

@ -1949,6 +1949,7 @@ delta_str(PyDateTime_Delta *self)
/* Pickle support, a simple use of __reduce__. */
/* __getstate__ isn't exposed */
static PyObject *
delta_getstate(PyDateTime_Delta *self)
{
@ -1979,9 +1980,6 @@ static PyMemberDef delta_members[] = {
};
static PyMethodDef delta_methods[] = {
{"__getstate__", (PyCFunction)delta_getstate, METH_NOARGS,
PyDoc_STR("__getstate__() -> state")},
{"__reduce__", (PyCFunction)delta_reduce, METH_NOARGS,
PyDoc_STR("__reduce__() -> (cls, state)")},
@ -2525,6 +2523,7 @@ date_weekday(PyDateTime_Date *self)
/* Pickle support, a simple use of __reduce__. */
/* __getstate__ isn't exposed */
static PyObject *
date_getstate(PyDateTime_Date *self)
{
@ -2591,9 +2590,6 @@ static PyMethodDef date_methods[] = {
{"replace", (PyCFunction)date_replace, METH_KEYWORDS,
PyDoc_STR("Return date with new specified fields.")},
{"__getstate__", (PyCFunction)date_getstate, METH_NOARGS,
PyDoc_STR("__getstate__() -> state")},
{"__reduce__", (PyCFunction)date_reduce, METH_NOARGS,
PyDoc_STR("__reduce__() -> (cls, state)")},
@ -3340,6 +3336,7 @@ time_nonzero(PyDateTime_Time *self)
/* Let basestate be the non-tzinfo data string.
* If tzinfo is None, this returns (basestate,), else (basestate, tzinfo).
* So it's a tuple in any (non-error) case.
* __getstate__ isn't exposed.
*/
static PyObject *
time_getstate(PyDateTime_Time *self)
@ -3386,9 +3383,6 @@ static PyMethodDef time_methods[] = {
{"replace", (PyCFunction)time_replace, METH_KEYWORDS,
PyDoc_STR("Return time with new specified fields.")},
{"__getstate__", (PyCFunction)time_getstate, METH_NOARGS,
PyDoc_STR("__getstate__() -> state")},
{"__reduce__", (PyCFunction)time_reduce, METH_NOARGS,
PyDoc_STR("__reduce__() -> (cls, state)")},
@ -4340,6 +4334,7 @@ datetime_utctimetuple(PyDateTime_DateTime *self)
/* Let basestate be the non-tzinfo data string.
* If tzinfo is None, this returns (basestate,), else (basestate, tzinfo).
* So it's a tuple in any (non-error) case.
* __getstate__ isn't exposed.
*/
static PyObject *
datetime_getstate(PyDateTime_DateTime *self)
@ -4431,9 +4426,6 @@ static PyMethodDef datetime_methods[] = {
{"astimezone", (PyCFunction)datetime_astimezone, METH_KEYWORDS,
PyDoc_STR("tz -> convert to local time in new timezone tz\n")},
{"__getstate__", (PyCFunction)datetime_getstate, METH_NOARGS,
PyDoc_STR("__getstate__() -> state")},
{"__reduce__", (PyCFunction)datetime_reduce, METH_NOARGS,
PyDoc_STR("__reduce__() -> (cls, state)")},
@ -4530,46 +4522,6 @@ initdatetime(void)
if (PyType_Ready(&PyDateTime_TZInfoType) < 0)
return;
/* Make __getnewargs__ a true alias for __getstate__ */
{
PyObject *d, *f;
d = PyDateTime_DateType.tp_dict;
f = PyDict_GetItemString(d, "__getstate__");
if (f != NULL) {
if (PyDict_SetItemString(d, "__getnewargs__", f) < 0)
return;
}
d = PyDateTime_DateTimeType.tp_dict;
f = PyDict_GetItemString(d, "__getstate__");
if (f != NULL) {
if (PyDict_SetItemString(d, "__getnewargs__", f) < 0)
return;
}
d = PyDateTime_DeltaType.tp_dict;
f = PyDict_GetItemString(d, "__getstate__");
if (f != NULL) {
if (PyDict_SetItemString(d, "__getnewargs__", f) < 0)
return;
}
d = PyDateTime_TimeType.tp_dict;
f = PyDict_GetItemString(d, "__getstate__");
if (f != NULL) {
if (PyDict_SetItemString(d, "__getnewargs__", f) < 0)
return;
}
d = PyDateTime_TZInfoType.tp_dict;
f = PyDict_GetItemString(d, "__getstate__");
if (f != NULL) {
if (PyDict_SetItemString(d, "__getnewargs__", f) < 0)
return;
}
}
/* timedelta values */
d = PyDateTime_DeltaType.tp_dict;