[Python-checkins] r69752 - in python/branches/py3k: Lib/test/test_itertools.py Modules/itertoolsmodule.c

raymond.hettinger python-checkins at python.org
Thu Feb 19 03:44:01 CET 2009


Author: raymond.hettinger
Date: Thu Feb 19 03:44:01 2009
New Revision: 69752

Log:
Add keyword arg support to itertools.repeat().

Modified:
   python/branches/py3k/Lib/test/test_itertools.py
   python/branches/py3k/Modules/itertoolsmodule.c

Modified: python/branches/py3k/Lib/test/test_itertools.py
==============================================================================
--- python/branches/py3k/Lib/test/test_itertools.py	(original)
+++ python/branches/py3k/Lib/test/test_itertools.py	Thu Feb 19 03:44:01 2009
@@ -640,6 +640,7 @@
         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(lzip(range(3),repeat('a')),
                          [(0, 'a'), (1, 'a'), (2, 'a')])
         self.assertEqual(list(repeat('a', 3)), ['a', 'a', 'a'])

Modified: python/branches/py3k/Modules/itertoolsmodule.c
==============================================================================
--- python/branches/py3k/Modules/itertoolsmodule.c	(original)
+++ python/branches/py3k/Modules/itertoolsmodule.c	Thu Feb 19 03:44:01 2009
@@ -3106,11 +3106,10 @@
 	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)
@@ -3178,8 +3177,8 @@
 };
 
 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 = {


More information about the Python-checkins mailing list