summaryrefslogtreecommitdiffstats
path: root/Modules/_datetimemodule.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2022-04-06 17:00:14 (GMT)
committerGitHub <noreply@github.com>2022-04-06 17:00:14 (GMT)
commit884eba3c76916889fd6bff3b37b8552bfb4f9566 (patch)
tree51fd55d6170cdff327ac11d70f1e5ff1aa7e735a /Modules/_datetimemodule.c
parentf82f9ce3239b9a7e6ffa278658dd9858f64a3c14 (diff)
downloadcpython-884eba3c76916889fd6bff3b37b8552bfb4f9566.zip
cpython-884eba3c76916889fd6bff3b37b8552bfb4f9566.tar.gz
cpython-884eba3c76916889fd6bff3b37b8552bfb4f9566.tar.bz2
bpo-26579: Add object.__getstate__(). (GH-2821)
Copying and pickling instances of subclasses of builtin types bytearray, set, frozenset, collections.OrderedDict, collections.deque, weakref.WeakSet, and datetime.tzinfo now copies and pickles instance attributes implemented as slots.
Diffstat (limited to 'Modules/_datetimemodule.c')
-rw-r--r--Modules/_datetimemodule.c30
1 files changed, 4 insertions, 26 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index ae97190..fc766c3 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -3736,9 +3736,8 @@ static PyObject *
tzinfo_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *args, *state;
- PyObject *getinitargs, *getstate;
+ PyObject *getinitargs;
_Py_IDENTIFIER(__getinitargs__);
- _Py_IDENTIFIER(__getstate__);
if (_PyObject_LookupAttrId(self, &PyId___getinitargs__, &getinitargs) < 0) {
return NULL;
@@ -3754,34 +3753,13 @@ tzinfo_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
return NULL;
}
- if (_PyObject_LookupAttrId(self, &PyId___getstate__, &getstate) < 0) {
+ state = _PyObject_GetState(self);
+ if (state == NULL) {
Py_DECREF(args);
return NULL;
}
- if (getstate != NULL) {
- state = PyObject_CallNoArgs(getstate);
- Py_DECREF(getstate);
- if (state == NULL) {
- Py_DECREF(args);
- return NULL;
- }
- }
- else {
- PyObject **dictptr;
- state = Py_None;
- dictptr = _PyObject_GetDictPtr(self);
- if (dictptr && *dictptr && PyDict_GET_SIZE(*dictptr)) {
- state = *dictptr;
- }
- Py_INCREF(state);
- }
- if (state == Py_None) {
- Py_DECREF(state);
- return Py_BuildValue("(ON)", Py_TYPE(self), args);
- }
- else
- return Py_BuildValue("(ONN)", Py_TYPE(self), args, state);
+ return Py_BuildValue("(ONN)", Py_TYPE(self), args, state);
}
static PyMethodDef tzinfo_methods[] = {