mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Add keyword arg support to itertools.repeat().
This commit is contained in:
		
							parent
							
								
									15a4950da1
								
							
						
					
					
						commit
						f4bb7f2100
					
				
					 2 changed files with 7 additions and 7 deletions
				
			
		|  | @ -640,6 +640,7 @@ def product2(*args, **kwds): | |||
|         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']) | ||||
|  |  | |||
|  | @ -3106,11 +3106,10 @@ repeat_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | |||
| 	repeatobject *ro; | ||||
| 	PyObject *element; | ||||
| 	Py_ssize_t cnt = -1; | ||||
| 	static char *kwargs[] = {"object", "times", NULL}; | ||||
|   | ||||
| 	if (type == &repeat_type && !_PyArg_NoKeywords("repeat()", kwds)) | ||||
| 		return NULL; | ||||
| 
 | ||||
| 	if (!PyArg_ParseTuple(args, "O|n:repeat", &element, &cnt)) | ||||
|  	if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|n:repeat", kwargs,  | ||||
| 					 &element, &cnt)) | ||||
| 		return NULL; | ||||
| 
 | ||||
| 	if (PyTuple_Size(args) == 2 && cnt < 0) | ||||
|  | @ -3178,8 +3177,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 = { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Raymond Hettinger
						Raymond Hettinger