from test.support import (TESTFN, captured_output, check_impl_detail,
cpython_only, gc_collect, run_unittest, unlink)
+class NaiveException(Exception):
+ def __init__(self, x):
+ self.x = x
+
+class SlottedNaiveException(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):
{'args' : ('\u3042', 0, 1, 'ouch'),
'object' : '\u3042', 'reason' : 'ouch',
'start' : 0, 'end' : 1}),
+ (NaiveException, ('foo',),
+ {'args': ('foo',), 'x': 'foo'}),
+ (SlottedNaiveException, ('foo',),
+ {'args': ('foo',), 'x': 'foo'}),
]
try:
exceptionList.append(
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:
self->dict = NULL;
self->traceback = self->cause = self->context = NULL;
+ if (args) {
+ self->args = args;
+ Py_INCREF(args);
+ return (PyObject *)self;
+ }
+
self->args = PyTuple_New(0);
if (!self->args) {
Py_DECREF(self);
static int
BaseException_init(PyBaseExceptionObject *self, PyObject *args, PyObject *kwds)
{
+ PyObject *tmp;
+
if (!_PyArg_NoKeywords(Py_TYPE(self)->tp_name, kwds))
return -1;
- Py_DECREF(self->args);
+ tmp = self->args;
self->args = args;
Py_INCREF(self->args);
+ Py_XDECREF(tmp);
return 0;
}