]> granicus.if.org Git - python/commitdiff
PyErr_NewException now accepts a tuple of base classes as its
authorGeorg Brandl <georg@python.org>
Tue, 23 May 2006 11:17:21 +0000 (11:17 +0000)
committerGeorg Brandl <georg@python.org>
Tue, 23 May 2006 11:17:21 +0000 (11:17 +0000)
"base" parameter.

Doc/api/exceptions.tex
Misc/NEWS
Python/errors.c

index ed419a8adc15557519a2047687518ff0673a25dc..e1bfb3800b733d762753539779387515776c003e 100644 (file)
@@ -341,7 +341,8 @@ for each thread.
   The \member{__module__} attribute of the new class is set to the
   first part (up to the last dot) of the \var{name} argument, and the
   class name is set to the last part (after the last dot).  The
-  \var{base} argument can be used to specify an alternate base class.
+  \var{base} argument can be used to specify alternate base classes;
+  it can either be only one class or a tuple of classes.
   The \var{dict} argument can be used to specify a dictionary of class
   variables and methods.
 \end{cfuncdesc}
index 445110f1b274512d0d12b27cb310f031733087fb..cfb1d15a70407cc4955593e0d910baa79169f146 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.5 alpha 3?
 Core and builtins
 -----------------
 
+- PyErr_NewException now accepts a tuple of base classes as its
+  "base" parameter.
+
 - Patch #876206: function call speedup by retaining allocated frame
   objects.
 
index 8327f5395d3ab8683497b37c244230f3152e9454..baf52ff1b9eba09c645c7c56e56751ffe525999e 100644 (file)
@@ -527,6 +527,7 @@ PyErr_Format(PyObject *exception, const char *format, ...)
 }
 
 
+
 PyObject *
 PyErr_NewException(char *name, PyObject *base, PyObject *dict)
 {
@@ -559,9 +560,15 @@ PyErr_NewException(char *name, PyObject *base, PyObject *dict)
        classname = PyString_FromString(dot+1);
        if (classname == NULL)
                goto failure;
-       bases = PyTuple_Pack(1, base);
-       if (bases == NULL)
-               goto failure;
+       if (PyTuple_Check(base)) {
+               bases = base;
+               /* INCREF as we create a new ref in the else branch */
+               Py_INCREF(bases);
+       } else {
+               bases = PyTuple_Pack(1, base);
+               if (bases == NULL)
+                       goto failure;
+       }
        result = PyClass_New(bases, dict, classname);
   failure:
        Py_XDECREF(bases);