# HG changeset patch # Parent 51ac5f06dd0436b6429500a17f4b35431ad53089 diff -r 51ac5f06dd04 -r 9eeb6f517ede Lib/test/test_exceptions.py --- a/Lib/test/test_exceptions.py Tue Jul 24 03:45:39 2012 -0700 +++ b/Lib/test/test_exceptions.py Fri Jul 27 11:49:59 2012 +0100 @@ -10,6 +10,15 @@ from test.support import (TESTFN, unlink, run_unittest, captured_output, gc_collect, cpython_only, no_tracing) +class NaiveException(Exception): + def __init__(self, x): + self.x = x + +class SlotedNaiveException(Exception): + __slots__ = ('x',) + def __init__(self, x): + self.x = x + # XXX This is not really enough, each *operation* should be tested! class ExceptionTests(unittest.TestCase): @@ -296,6 +305,10 @@ {'args' : ('\u3042', 0, 1, 'ouch'), 'object' : '\u3042', 'reason' : 'ouch', 'start' : 0, 'end' : 1}), + (NaiveException, ('foo',), + {'args': ('foo',), 'x': 'foo'}), + (SlotedNaiveException, ('foo',), + {'args': ('foo',), 'x': 'foo'}), ] try: # More tests are in test_WindowsError @@ -316,7 +329,8 @@ raise else: # Verify module name - self.assertEqual(type(e).__module__, 'builtins') + if not type(e).__name__.endswith('NaiveException'): + self.assertEqual(type(e).__module__, 'builtins') # Verify no ref leaks in Exc_str() s = str(e) for checkArgName in expected: diff -r 51ac5f06dd04 -r 9eeb6f517ede Objects/exceptions.c --- a/Objects/exceptions.c Tue Jul 24 03:45:39 2012 -0700 +++ b/Objects/exceptions.c Fri Jul 27 11:49:59 2012 +0100 @@ -44,6 +44,12 @@ 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);