a = self.type2test(range(10))
a[::2] = tuple(range(5))
self.assertEqual(a, self.type2test([0, 1, 1, 3, 2, 5, 3, 7, 4, 9]))
+
+ def test_constructor_exception_handling(self):
+ # Bug #1242657
+ class F(object):
+ def __iter__(self):
+ yield 23
+ def __len__(self):
+ raise KeyboardInterrupt
+ self.assertRaises(KeyboardInterrupt, list, F())
/* Guess result size and allocate space. */
n = PyObject_Size(v);
if (n < 0) {
+ if (!PyErr_ExceptionMatches(PyExc_TypeError) &&
+ !PyErr_ExceptionMatches(PyExc_AttributeError)) {
+ Py_DECREF(it);
+ return NULL;
+ }
PyErr_Clear();
n = 10; /* arbitrary */
}
/* Guess a result list size. */
n = PyObject_Size(b);
if (n < 0) {
+ if (!PyErr_ExceptionMatches(PyExc_TypeError) &&
+ !PyErr_ExceptionMatches(PyExc_AttributeError)) {
+ Py_DECREF(it);
+ return NULL;
+ }
PyErr_Clear();
n = 8; /* arbitrary */
}
/* Guess a result list size. */
len = PyObject_Size(seq);
if (len < 0) {
+ if (!PyErr_ExceptionMatches(PyExc_TypeError) &&
+ !PyErr_ExceptionMatches(PyExc_AttributeError)) {
+ goto Fail_it;
+ }
PyErr_Clear();
len = 8; /* arbitrary */
}
/* Update len. */
curlen = PyObject_Size(curseq);
if (curlen < 0) {
+ if (!PyErr_ExceptionMatches(PyExc_TypeError) &&
+ !PyErr_ExceptionMatches(PyExc_AttributeError)) {
+ goto Fail_2;
+ }
PyErr_Clear();
curlen = 8; /* arbitrary */
}
PyObject *item = PyTuple_GET_ITEM(args, i);
int thislen = PyObject_Size(item);
if (thislen < 0) {
+ if (!PyErr_ExceptionMatches(PyExc_TypeError) &&
+ !PyErr_ExceptionMatches(PyExc_AttributeError)) {
+ return NULL;
+ }
PyErr_Clear();
len = -1;
break;