Skip to content

Commit 9986e86

Browse files
author
Rémi Lapeyre
committed
Create self.kwargs only if accessed
1 parent 88ba13e commit 9986e86

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

Objects/exceptions.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,8 @@ BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
5656
}
5757
}
5858

59-
if (kwds) {
60-
self->kwargs = kwds;
61-
Py_INCREF(kwds);
62-
} else {
63-
self->kwargs = PyDict_New();
64-
if (!self->kwargs) {
65-
Py_DECREF(self);
66-
return NULL;
67-
}
68-
}
59+
self->kwargs = kwds;
60+
Py_XINCREF(kwds);
6961

7062
return (PyObject *)self;
7163
}
@@ -345,9 +337,9 @@ BaseException_set_args(PyBaseExceptionObject *self, PyObject *val, void *Py_UNUS
345337
static PyObject *
346338
BaseException_get_kwargs(PyBaseExceptionObject *self, void *Py_UNUSED(ignored)) {
347339
if (self->kwargs == NULL) {
348-
Py_RETURN_NONE;
340+
self->kwargs = PyDict_New();
349341
}
350-
Py_INCREF(self->kwargs);
342+
Py_XINCREF(self->kwargs);
351343
return self->kwargs;
352344
}
353345

0 commit comments

Comments
 (0)