mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
Issue #1692335: Move initial args assignment to BaseException.__new__
to help pickling of naive subclasses.
This commit is contained in:
parent
e4c0799d9c
commit
5562d9dc5d
3 changed files with 28 additions and 2 deletions
|
|
@ -44,6 +44,12 @@ BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
self->traceback = self->cause = self->context = NULL;
|
||||
self->suppress_context = 0;
|
||||
|
||||
if (args) {
|
||||
self->args = args;
|
||||
Py_INCREF(args);
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
self->args = PyTuple_New(0);
|
||||
if (!self->args) {
|
||||
Py_DECREF(self);
|
||||
|
|
@ -56,12 +62,15 @@ BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
static int
|
||||
BaseException_init(PyBaseExceptionObject *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PyObject *tmp;
|
||||
|
||||
if (!_PyArg_NoKeywords(Py_TYPE(self)->tp_name, kwds))
|
||||
return -1;
|
||||
|
||||
Py_XDECREF(self->args);
|
||||
tmp = self->args;
|
||||
self->args = args;
|
||||
Py_INCREF(self->args);
|
||||
Py_XDECREF(tmp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue