]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add keyword arg support to itertools.repeat().
authorRaymond Hettinger <python@rcn.com>
Thu, 19 Feb 2009 02:38:25 +0000 (02:38 +0000)
committerRaymond Hettinger <python@rcn.com>
Thu, 19 Feb 2009 02:38:25 +0000 (02:38 +0000)
Lib/test/test_itertools.py
Modules/itertoolsmodule.c

index 2cdb1d7dc0ba3ecc8c28b4220c4450e28b11fa83..81a052b862df5f560b5a0cbbc298cfc78ceaf547 100644 (file)
@@ -632,6 +632,7 @@ class TestBasicOps(unittest.TestCase):
         self.assertNotEqual(len(set(map(id, list(product('abc', 'def'))))), 1)
 
     def test_repeat(self):
+        self.assertEqual(list(repeat(object='a', times=3)), ['a', 'a', 'a'])
         self.assertEqual(zip(xrange(3),repeat('a')),
                          [(0, 'a'), (1, 'a'), (2, 'a')])
         self.assertEqual(list(repeat('a', 3)), ['a', 'a', 'a'])
index 3c6d618bc1dcd364f6a4f3ef9f512c95d5b4e6fc..4aa02b62012fba181e716e4bbbebeb12311eaf60 100644 (file)
@@ -3617,11 +3617,10 @@ repeat_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
        repeatobject *ro;
        PyObject *element;
        Py_ssize_t cnt = -1;
-
-       if (type == &repeat_type && !_PyArg_NoKeywords("repeat()", kwds))
-               return NULL;
-
-       if (!PyArg_ParseTuple(args, "O|n:repeat", &element, &cnt))
+       static char *kwargs[] = {"object", "times", NULL};
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|n:repeat", kwargs, 
+                                        &element, &cnt))
                return NULL;
 
        if (PyTuple_Size(args) == 2 && cnt < 0)
@@ -3699,8 +3698,8 @@ static PyMethodDef repeat_methods[] = {
 };
 
 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\
+"repeat(object [,times]) -> create an iterator which returns the object\n\
+for the specified number of times.  If not specified, returns the object\n\
 endlessly.");
 
 static PyTypeObject repeat_type = {