summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-11-21 22:29:42 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-11-21 22:29:42 (GMT)
commit546ce65968921f52f1c79a7218e57dc237dbe436 (patch)
treeb63e6a32e8e0ca3893f6914367ecdbcd36e19c67 /Modules
parentf89854f89c7d4f625ad8d35783a30b7a48bd0e76 (diff)
downloadcpython-546ce65968921f52f1c79a7218e57dc237dbe436.zip
cpython-546ce65968921f52f1c79a7218e57dc237dbe436.tar.gz
cpython-546ce65968921f52f1c79a7218e57dc237dbe436.tar.bz2
Issue #28752: Restored the __reduce__() methods of datetime objects.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_datetimemodule.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index d0ddcc2..c09cce9 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -3955,15 +3955,21 @@ time_getstate(PyDateTime_Time *self, int proto)
}
static PyObject *
-time_reduce(PyDateTime_Time *self, PyObject *args)
+time_reduce_ex(PyDateTime_Time *self, PyObject *args)
{
- int proto = 0;
- if (!PyArg_ParseTuple(args, "|i:__reduce_ex__", &proto))
+ int proto;
+ if (!PyArg_ParseTuple(args, "i:__reduce_ex__", &proto))
return NULL;
return Py_BuildValue("(ON)", Py_TYPE(self), time_getstate(self, proto));
}
+static PyObject *
+time_reduce(PyDateTime_Time *self, PyObject *arg)
+{
+ return Py_BuildValue("(ON)", Py_TYPE(self), time_getstate(self, 2));
+}
+
static PyMethodDef time_methods[] = {
{"isoformat", (PyCFunction)time_isoformat, METH_VARARGS | METH_KEYWORDS,
@@ -3989,9 +3995,12 @@ static PyMethodDef time_methods[] = {
{"replace", (PyCFunction)time_replace, METH_VARARGS | METH_KEYWORDS,
PyDoc_STR("Return time with new specified fields.")},
- {"__reduce_ex__", (PyCFunction)time_reduce, METH_VARARGS,
+ {"__reduce_ex__", (PyCFunction)time_reduce_ex, METH_VARARGS,
PyDoc_STR("__reduce_ex__(proto) -> (cls, state)")},
+ {"__reduce__", (PyCFunction)time_reduce, METH_NOARGS,
+ PyDoc_STR("__reduce__() -> (cls, state)")},
+
{NULL, NULL}
};
@@ -5420,15 +5429,21 @@ datetime_getstate(PyDateTime_DateTime *self, int proto)
}
static PyObject *
-datetime_reduce(PyDateTime_DateTime *self, PyObject *args)
+datetime_reduce_ex(PyDateTime_DateTime *self, PyObject *args)
{
- int proto = 0;
- if (!PyArg_ParseTuple(args, "|i:__reduce_ex__", &proto))
+ int proto;
+ if (!PyArg_ParseTuple(args, "i:__reduce_ex__", &proto))
return NULL;
return Py_BuildValue("(ON)", Py_TYPE(self), datetime_getstate(self, proto));
}
+static PyObject *
+datetime_reduce(PyDateTime_DateTime *self, PyObject *arg)
+{
+ return Py_BuildValue("(ON)", Py_TYPE(self), datetime_getstate(self, 2));
+}
+
static PyMethodDef datetime_methods[] = {
/* Class methods: */
@@ -5503,9 +5518,12 @@ static PyMethodDef datetime_methods[] = {
{"astimezone", (PyCFunction)datetime_astimezone, METH_VARARGS | METH_KEYWORDS,
PyDoc_STR("tz -> convert to local time in new timezone tz\n")},
- {"__reduce_ex__", (PyCFunction)datetime_reduce, METH_VARARGS,
+ {"__reduce_ex__", (PyCFunction)datetime_reduce_ex, METH_VARARGS,
PyDoc_STR("__reduce_ex__(proto) -> (cls, state)")},
+ {"__reduce__", (PyCFunction)datetime_reduce, METH_NOARGS,
+ PyDoc_STR("__reduce__() -> (cls, state)")},
+
{NULL, NULL}
};