self.assertRaises(TypeError, list, tee(N(s))[0])
self.assertRaises(ZeroDivisionError, list, tee(E(s))[0])
+class LengthTransparency(unittest.TestCase):
+
+ def test_repeat(self):
+ self.assertEqual(len(repeat(None, 50)), 50)
+ self.assertRaises(TypeError, len, repeat(None))
+
class RegressionTests(unittest.TestCase):
def test_sf_793826(self):
def test_main(verbose=None):
test_classes = (TestBasicOps, TestVariousIteratorArgs, TestGC,
- RegressionTests)
+ RegressionTests, LengthTransparency)
test_support.run_unittest(*test_classes)
# verify reference counting
return ro->element;
}
+static int
+repeat_len(repeatobject *ro)
+{
+ if (ro->cnt == -1)
+ PyErr_SetString(PyExc_TypeError, "len() of unsized object");
+ return (int)(ro->cnt);
+}
+
+static PySequenceMethods repeat_as_sequence = {
+ (inquiry)repeat_len, /* sq_length */
+ 0, /* sq_concat */
+};
+
PyDoc_STRVAR(repeat_doc,
"repeat(element [,times]) -> create an iterator which returns the element\n\
for the specified number of times. If not specified, returns the element\n\
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
- 0, /* tp_as_sequence */
+ &repeat_as_sequence, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */