Skip to content

Commit 658d513

Browse files
committed
PyErr_NewException now accepts a tuple of base classes as its
"base" parameter.
1 parent da89b99 commit 658d513

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

Doc/api/exceptions.tex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ \chapter{Exception Handling \label{exceptionHandling}}
341341
The \member{__module__} attribute of the new class is set to the
342342
first part (up to the last dot) of the \var{name} argument, and the
343343
class name is set to the last part (after the last dot). The
344-
\var{base} argument can be used to specify an alternate base class.
344+
\var{base} argument can be used to specify alternate base classes;
345+
it can either be only one class or a tuple of classes.
345346
The \var{dict} argument can be used to specify a dictionary of class
346347
variables and methods.
347348
\end{cfuncdesc}

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ What's New in Python 2.5 alpha 3?
1212
Core and builtins
1313
-----------------
1414

15+
- PyErr_NewException now accepts a tuple of base classes as its
16+
"base" parameter.
17+
1518
- Patch #876206: function call speedup by retaining allocated frame
1619
objects.
1720

Python/errors.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ PyErr_Format(PyObject *exception, const char *format, ...)
527527
}
528528

529529

530+
530531
PyObject *
531532
PyErr_NewException(char *name, PyObject *base, PyObject *dict)
532533
{
@@ -559,9 +560,15 @@ PyErr_NewException(char *name, PyObject *base, PyObject *dict)
559560
classname = PyString_FromString(dot+1);
560561
if (classname == NULL)
561562
goto failure;
562-
bases = PyTuple_Pack(1, base);
563-
if (bases == NULL)
564-
goto failure;
563+
if (PyTuple_Check(base)) {
564+
bases = base;
565+
/* INCREF as we create a new ref in the else branch */
566+
Py_INCREF(bases);
567+
} else {
568+
bases = PyTuple_Pack(1, base);
569+
if (bases == NULL)
570+
goto failure;
571+
}
565572
result = PyClass_New(bases, dict, classname);
566573
failure:
567574
Py_XDECREF(bases);

0 commit comments

Comments
 (0)