Commit b57f8f02 authored by Tim Peters's avatar Tim Peters

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!).
parent 874d9bcb
...@@ -278,8 +278,6 @@ class TestTimeDelta(unittest.TestCase): ...@@ -278,8 +278,6 @@ class TestTimeDelta(unittest.TestCase):
def test_pickling(self): def test_pickling(self):
args = 12, 34, 56 args = 12, 34, 56
orig = timedelta(*args) orig = timedelta(*args)
state = orig.__getstate__()
self.assertEqual(args, state)
for pickler, unpickler, proto in pickle_choices: for pickler, unpickler, proto in pickle_choices:
green = pickler.dumps(orig, proto) green = pickler.dumps(orig, proto)
derived = unpickler.loads(green) derived = unpickler.loads(green)
...@@ -832,8 +830,6 @@ class TestDate(unittest.TestCase): ...@@ -832,8 +830,6 @@ class TestDate(unittest.TestCase):
def test_pickling(self): def test_pickling(self):
args = 6, 7, 23 args = 6, 7, 23
orig = self.theclass(*args) orig = self.theclass(*args)
state = orig.__getstate__()
self.assertEqual(state, ('\x00\x06\x07\x17',), self.theclass)
for pickler, unpickler, proto in pickle_choices: for pickler, unpickler, proto in pickle_choices:
green = pickler.dumps(orig, proto) green = pickler.dumps(orig, proto)
derived = unpickler.loads(green) derived = unpickler.loads(green)
...@@ -1186,8 +1182,6 @@ class TestDateTime(TestDate): ...@@ -1186,8 +1182,6 @@ class TestDateTime(TestDate):
def test_pickling(self): def test_pickling(self):
args = 6, 7, 23, 20, 59, 1, 64**2 args = 6, 7, 23, 20, 59, 1, 64**2
orig = self.theclass(*args) 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: for pickler, unpickler, proto in pickle_choices:
green = pickler.dumps(orig, proto) green = pickler.dumps(orig, proto)
derived = unpickler.loads(green) derived = unpickler.loads(green)
...@@ -1567,8 +1561,6 @@ class TestTime(unittest.TestCase): ...@@ -1567,8 +1561,6 @@ class TestTime(unittest.TestCase):
def test_pickling(self): def test_pickling(self):
args = 20, 59, 16, 64**2 args = 20, 59, 16, 64**2
orig = self.theclass(*args) orig = self.theclass(*args)
state = orig.__getstate__()
self.assertEqual(state, ('\x14\x3b\x10\x00\x10\x00',))
for pickler, unpickler, proto in pickle_choices: for pickler, unpickler, proto in pickle_choices:
green = pickler.dumps(orig, proto) green = pickler.dumps(orig, proto)
derived = unpickler.loads(green) derived = unpickler.loads(green)
...@@ -1877,8 +1869,6 @@ class TestTimeTZ(TestTime, TZInfoBase): ...@@ -1877,8 +1869,6 @@ class TestTimeTZ(TestTime, TZInfoBase):
# Try one without a tzinfo. # Try one without a tzinfo.
args = 20, 59, 16, 64**2 args = 20, 59, 16, 64**2
orig = self.theclass(*args) orig = self.theclass(*args)
state = orig.__getstate__()
self.assertEqual(state, ('\x14\x3b\x10\x00\x10\x00',))
for pickler, unpickler, proto in pickle_choices: for pickler, unpickler, proto in pickle_choices:
green = pickler.dumps(orig, proto) green = pickler.dumps(orig, proto)
derived = unpickler.loads(green) derived = unpickler.loads(green)
...@@ -2080,8 +2070,6 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase): ...@@ -2080,8 +2070,6 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase):
# Try one without a tzinfo. # Try one without a tzinfo.
args = 6, 7, 23, 20, 59, 1, 64**2 args = 6, 7, 23, 20, 59, 1, 64**2
orig = self.theclass(*args) 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: for pickler, unpickler, proto in pickle_choices:
green = pickler.dumps(orig, proto) green = pickler.dumps(orig, proto)
derived = unpickler.loads(green) derived = unpickler.loads(green)
......
...@@ -131,8 +131,8 @@ Extension modules ...@@ -131,8 +131,8 @@ Extension modules
The pickle format of date, time and datetime objects has changed The pickle format of date, time and datetime objects has changed
completely. The undocumented pickler and unpickler functions no completely. The undocumented pickler and unpickler functions no
longer exist. The undocumented __setstate__() methods no longer longer exist. The undocumented __setstate__() and __getstate__()
exist either. methods no longer exist either.
Library Library
------- -------
......
...@@ -1949,6 +1949,7 @@ delta_str(PyDateTime_Delta *self) ...@@ -1949,6 +1949,7 @@ delta_str(PyDateTime_Delta *self)
/* Pickle support, a simple use of __reduce__. */ /* Pickle support, a simple use of __reduce__. */
/* __getstate__ isn't exposed */
static PyObject * static PyObject *
delta_getstate(PyDateTime_Delta *self) delta_getstate(PyDateTime_Delta *self)
{ {
...@@ -1979,9 +1980,6 @@ static PyMemberDef delta_members[] = { ...@@ -1979,9 +1980,6 @@ static PyMemberDef delta_members[] = {
}; };
static PyMethodDef delta_methods[] = { static PyMethodDef delta_methods[] = {
{"__getstate__", (PyCFunction)delta_getstate, METH_NOARGS,
PyDoc_STR("__getstate__() -> state")},
{"__reduce__", (PyCFunction)delta_reduce, METH_NOARGS, {"__reduce__", (PyCFunction)delta_reduce, METH_NOARGS,
PyDoc_STR("__reduce__() -> (cls, state)")}, PyDoc_STR("__reduce__() -> (cls, state)")},
...@@ -2525,6 +2523,7 @@ date_weekday(PyDateTime_Date *self) ...@@ -2525,6 +2523,7 @@ date_weekday(PyDateTime_Date *self)
/* Pickle support, a simple use of __reduce__. */ /* Pickle support, a simple use of __reduce__. */
/* __getstate__ isn't exposed */
static PyObject * static PyObject *
date_getstate(PyDateTime_Date *self) date_getstate(PyDateTime_Date *self)
{ {
...@@ -2591,9 +2590,6 @@ static PyMethodDef date_methods[] = { ...@@ -2591,9 +2590,6 @@ static PyMethodDef date_methods[] = {
{"replace", (PyCFunction)date_replace, METH_KEYWORDS, {"replace", (PyCFunction)date_replace, METH_KEYWORDS,
PyDoc_STR("Return date with new specified fields.")}, PyDoc_STR("Return date with new specified fields.")},
{"__getstate__", (PyCFunction)date_getstate, METH_NOARGS,
PyDoc_STR("__getstate__() -> state")},
{"__reduce__", (PyCFunction)date_reduce, METH_NOARGS, {"__reduce__", (PyCFunction)date_reduce, METH_NOARGS,
PyDoc_STR("__reduce__() -> (cls, state)")}, PyDoc_STR("__reduce__() -> (cls, state)")},
...@@ -3340,6 +3336,7 @@ time_nonzero(PyDateTime_Time *self) ...@@ -3340,6 +3336,7 @@ time_nonzero(PyDateTime_Time *self)
/* Let basestate be the non-tzinfo data string. /* Let basestate be the non-tzinfo data string.
* If tzinfo is None, this returns (basestate,), else (basestate, tzinfo). * If tzinfo is None, this returns (basestate,), else (basestate, tzinfo).
* So it's a tuple in any (non-error) case. * So it's a tuple in any (non-error) case.
* __getstate__ isn't exposed.
*/ */
static PyObject * static PyObject *
time_getstate(PyDateTime_Time *self) time_getstate(PyDateTime_Time *self)
...@@ -3386,9 +3383,6 @@ static PyMethodDef time_methods[] = { ...@@ -3386,9 +3383,6 @@ static PyMethodDef time_methods[] = {
{"replace", (PyCFunction)time_replace, METH_KEYWORDS, {"replace", (PyCFunction)time_replace, METH_KEYWORDS,
PyDoc_STR("Return time with new specified fields.")}, PyDoc_STR("Return time with new specified fields.")},
{"__getstate__", (PyCFunction)time_getstate, METH_NOARGS,
PyDoc_STR("__getstate__() -> state")},
{"__reduce__", (PyCFunction)time_reduce, METH_NOARGS, {"__reduce__", (PyCFunction)time_reduce, METH_NOARGS,
PyDoc_STR("__reduce__() -> (cls, state)")}, PyDoc_STR("__reduce__() -> (cls, state)")},
...@@ -4340,6 +4334,7 @@ datetime_utctimetuple(PyDateTime_DateTime *self) ...@@ -4340,6 +4334,7 @@ datetime_utctimetuple(PyDateTime_DateTime *self)
/* Let basestate be the non-tzinfo data string. /* Let basestate be the non-tzinfo data string.
* If tzinfo is None, this returns (basestate,), else (basestate, tzinfo). * If tzinfo is None, this returns (basestate,), else (basestate, tzinfo).
* So it's a tuple in any (non-error) case. * So it's a tuple in any (non-error) case.
* __getstate__ isn't exposed.
*/ */
static PyObject * static PyObject *
datetime_getstate(PyDateTime_DateTime *self) datetime_getstate(PyDateTime_DateTime *self)
...@@ -4431,9 +4426,6 @@ static PyMethodDef datetime_methods[] = { ...@@ -4431,9 +4426,6 @@ static PyMethodDef datetime_methods[] = {
{"astimezone", (PyCFunction)datetime_astimezone, METH_KEYWORDS, {"astimezone", (PyCFunction)datetime_astimezone, METH_KEYWORDS,
PyDoc_STR("tz -> convert to local time in new timezone tz\n")}, 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, {"__reduce__", (PyCFunction)datetime_reduce, METH_NOARGS,
PyDoc_STR("__reduce__() -> (cls, state)")}, PyDoc_STR("__reduce__() -> (cls, state)")},
...@@ -4530,46 +4522,6 @@ initdatetime(void) ...@@ -4530,46 +4522,6 @@ initdatetime(void)
if (PyType_Ready(&PyDateTime_TZInfoType) < 0) if (PyType_Ready(&PyDateTime_TZInfoType) < 0)
return; 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 */ /* timedelta values */
d = PyDateTime_DeltaType.tp_dict; d = PyDateTime_DeltaType.tp_dict;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment